Question on 'Controller within Repeat' #4

sgentile opened this Issue Feb 27, 2013 · 6 comments

3 participants


I'm attempting something similiar here: 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)


    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?


    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 Feb 27, 2013
    @sgentile sgentile reopened this Feb 27, 2013

    "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 ( .


    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 ?


    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 Apr 8, 2013
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment