Reputation: 1710
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;
Upvotes: 0
Views: 588
Reputation: 38468
You forgot the Angular convention for attribute names:
<my-example my-variable="myVariable"></my-example>
Upvotes: 1