0
(function () {
'use strict';

angular.module('app')
    .controller('someController', ['$scope','localStorageService',someController])
    .directive('someDirective', someDirective)

function someController($scope, localStorageService){
    $scope.something = {
        someVar: localStorageService.get('someVar'),
    };
    console.log("someVar: " + $scope.something.someVar);//prints correct value
}

function someDirective(){
    return {
        template: {{something.someVar}}
    };
}

})();

In the html, where

<div ng-controller="someController"> 
    <div some-directive></div>    
</div>

is added, I keep getting a "Argument 'someController' is not a function, got undefined" even though someController executes fine when printing to console.

2
  • is the line template: {{something.someVar}} a mistype here or are you really missing the quotes? should be: template: '{{something.someVar}}'. Commented Nov 13, 2015 at 18:13
  • @Claies Ahhh yess that's what it was! Commented Nov 13, 2015 at 18:14

3 Answers 3

2

There is an error in the declaration of the template for the directive here.

template: {{something.someVar}} is missing the quotes.

It should be: template: '{{something.someVar}}'

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

Comments

0

can you try this ? this should be working

.controller('someController',someController)
.directive('someDirective', someDirective);

someController.$inject = ['$scope','localStorageService'];

Comments

0

Move the line that creates the controller and the directive to underneath the function declarations:

function someController($scope, localStorageService){
    $scope.something = {
        someVar: localStorageService.get('someVar'),
    };
    console.log("someVar: " + $scope.something.someVar);//prints correct value
}

function someDirective(){
    return {
        template: {{something.someVar}}
    };
}

angular.module('app')
    .controller('someController', ['$scope','localStorageService',someController])
    .directive('someDirective', someDirective);

1 Comment

^ not necessary and not the cause of the problem. also, sort of an ugly coding convention. your issue resides elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.