0

I have a controller like this:

var exampleController = function($scope, $stateParams){
    $scope.myVariable = $stateParams.id;
    console.log($scope.myVariable);
}

and a directive like:

var exampleDirective = function(){
    return {
        restrict: 'E',
        scope : {
            myVariable: '='
        },
        templateUrl: "myTemplate.html",
        link: function($scope){
               console.log($scope.myVariable);
        });
     };
}

in my html like:

<my-example myVariable="myVariable"></my-example>

Given the id in the url is 21, I got this:

21
undefiend

Do anybody know why I couldn't pass any $stateParams value so that the directive don't see it?

I've tried to pass a static value but it didn't worked too. Tried in this way within the controller:

$scope.myVariable = 26;
1
  • 1
    myVariable != my-variable Its a typo you missed the hyphen notation there on the view. i.e <my-example my-variable="myVariable"></my-example> Commented Jan 5, 2015 at 23:01

1 Answer 1

1

You forgot the Angular convention for attribute names:

<my-example my-variable="myVariable"></my-example>
Sign up to request clarification or add additional context in comments.

Comments

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.