Mid*_*sai 5 javascript angularjs
我试图在我使用时将数据发送到控制器的指令链接功能ng-clicked,但是我没有将数据发送到指令,该指令在第一次加载页面时调用
<h2 ng-click="clickMe(somedata)"> click </h2>
<my-directive my-key="myVal"> </my-directive>
Run Code Online (Sandbox Code Playgroud)
.controller('myController',function($scope){
$scope.clickMe=function(somedata){
$scope.myVal=somedata;
};
});
Run Code Online (Sandbox Code Playgroud)
.directive('myDirective',function(){
return{
restrict:'E',
scope:{
myKey:'='
},
templateUrl:'exampleTempl.html',
controller:'myController',
link:function(scope,elem,attr){
console.log(scope.myKey); // getting undefined
console.log(scope.myVal); //here i want the data from controller when i clicked on ng-click
}
}
});
Run Code Online (Sandbox Code Playgroud)
我希望这个对你有用;
.directive('myDirective',function(){
return{
restrict:'E',
scope:{
myKey:'=bindingmyVal'
},
templateUrl:'exampleTempl.html',
controller:'myController',
link:function(scope,elem,attr){
console.log(scope.myKey); //here i want the data from controller when i clicked on ng-click
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |