Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Question on 'Controller within Repeat' #4

Closed
sgentile opened this Issue · 6 comments

3 participants

@sgentile

I'm attempting something similiar here: http://www.bennadel.com/blog/2450-Using-ngController-With-ngRepeat-In-AngularJS.htm a master/detail approach.

Where I am going to bind a controller to a repeat, ie:

    My person controller:

    'use strict';

    define([], function() {

    function PersonController($scope) {
    }
    
    return PersonController;
    

    });

    However, I'm getting this error: Error: Argument 'PersonController' is not a function, got undefined

    I'm curious how to pull this controller and it's template in a repeater - (similiar perhaps to how Backbone would work)

    @matys84pl
    Owner

    Hi, can you create a plunkr/jsfiddle/etc with an example of what you're trying to achieve? It seems that when your repeater starts the controller is not yet downloaded and registered. Are you sure you have configured it to load with the partial that contains the repeater?

    @sgentile

    I have not - and that is where I'm not sure how I would do this. ie. it is part of the define that you tell it to include the controller ? With the dynamic javascript loading you have, do I have to register it first - ie. when creating the route do I need to specify there that it has a dependency on this personcontroller.js file ?

    @sgentile sgentile closed this
    @sgentile sgentile reopened this
    @matys84pl
    Owner

    "define" is a method of RequireJS - it defines the module and its dependencies. However, adding a dependency to your (repeater view) controller won't work as you have to also register it with angular - this is how my routeConfig works - it registers and uses it as a controller for particular view. It does not support loading multiple controllers (which I think is needed in your case), but it's quite easy to modify it to make it load as many controllers and directives as you want. There's also a way to load the controller on demand using custom directive - I have some prototypes on 'custom-directives' branch (https://github.com/matys84pl/angularjs-requirejs-lazy-controllers/blob/custom-directives/app/js/directives.js) .

    @sgentile

    Thanks - you've been very patient, appreciate you answering these questions.

    I have one more - as you have covered directives in here - how would you handle loading services ?

    @matys84pl
    Owner

    No worries!

    I've not looked at lazy loading of services, but I think the pattern could be similar to what I did with directives.

    @matys84pl matys84pl closed this
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Something went wrong with that request. Please try again.