0

I have a plunker here - http://plnkr.co/edit/ezKOtG9KJ6nD0068jpry?p=preview

I'm following this simple angular tutorial here - https://www.youtube.com/watch?v=aG8VD0KvUw4

When I run the code a get ReferenceError: Controller is not defined

Can anyone explain this or who to fix it.

        var app = angular.module('myApp', []);

        app.controller('ShieldCtrl', function($scope){

            $scope.sheildNames = [];

            this.addReigns = function(){

                $scope.shieldNames.push('Reigns: One');

            };

            this.addCollins = function(){

                $scope.shieldNames.push('Collins: Two');

            };

            this.addAmbrose = function(){

                $scope.shieldNames.push('Ambrose: Three');

            };

        })


        .directive('theshield', function(){

            return{
                restrict: 'E',
                scope: {},
                controller: 'ShieldCtrl',
                link: function(scope, element, attrs){

                    element.bind('mouseenter', function(){

                        console.log(scope.sheildName);

                    })
                }
            }
        })


        .directive('reigns', function(){
            return{
                require: 'theshield',
                link: function(scope, element, attrs, ShielCtrl){
                    ShieldCtrl.addReigns();
                }
            }
        })

        .directive('collins', function(){
            return{
                require: 'theshield',
                link: function(scope, element, attrs, ShielCtrl){
                    ShieldCtrl.addCollins();
                }
            }
        })

        .directive('ambrose', function(){
            return{
                require: 'theshield',
                link: function(scope, element, attrs, ShielCtrl){
                    ShieldCtrl.addAmbrose();
                }
            }
        })
2
  • 1
    your code has multiple issues causing it to not function correctly; the error you are asking about in this question is related to a simple typo: link: function(scope, element, attrs, ShielCtrl){. you are missing the d in all 3 functions. Once you fix that, though, you have some other issues to work out with your logic. Commented May 9, 2015 at 15:27
  • I think controller is fine but for directive you maybe have to add app.directive at each directive. Commented May 9, 2015 at 16:55

1 Answer 1

1

You have a simple spelling mistake, your directive controller dependencies are ShielCtrl and you're trying to use ShieldCtrl.

    .directive('reigns', function(){
        return{
            require: 'theshield',
            link: function(scope, element, attrs, ShielCtrl){
                ShieldCtrl.addReigns(); <-- CHECK spelling.
            }
        }
    })

Your next error is another spelling error: $scope.sheildNames = []; and you try to access the correct spelling: $scope.shieldNames.push('Reigns: One');

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.