&操作员未在指令的隔离范围内工作
& operator not working in the isolated scope of directive
我正在使用&(表达式绑定)运算符,但我无法在父控制器上触发函数。控制台上应该有输出,但我没有收到任何输出。
在HTML部分:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Directive &</title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="isolate_scope_&.js"></script>
</head>
<body ng-app="isolate_scope">
<div ng-controller="isolateScopeController">
<b>Ctrl Data</b>
<div ng-repeat="person in persons">
<p>{{person.name}}</p>
</div>
<b>Directive Data</b>
<div ng-repeat="person in persons">
<friends frnd="person.name"></friends>
</div>
<my-button isolatedFunction="printScopeToFile()"></my-button>
</div>
</body>
</html>
JS部分如下:
angular.module('isolate_scope', [])
.controller('isolateScopeController', function($scope){
$scope.persons = [
{
name:"tanmay",
age:"28"
},
{
name: "James",
age:"28"
},
{
name:"Rylan",
age:"26"
},
{
name:"Aditya",
age:"23"
}
];
$scope.printScopeToFile = function(){
console.log("printng to file.....");
for(var i in $scope.persons){
console.log("Name = " + $scope.persons[i].name + " Age = " + $scope.persons[i].age);
}
};
})
.directive('friends',function(){
return {
restrict :'E',
template: '<input type="text" ng-model="name">',
scope :{
name:'=frnd'
}
};
})
.directive('myButton',function(){
return {
restrict: 'E',
template: '<button ng-click="isolatedFunction()">callParentfunction</button>',
scope : {
isolatedFunction:"&"
}
};
});
同样的:http://jsfiddle.net/v51kob1q/
<my-button isolatedFunction...>
指令中的属性isolatedFunction
应该是isolated-function
,dash-delimited
属性
相关文章:
- 如何使用ngrepeat和双向绑定获得指令的隔离范围
- Angularjs无法将单选按钮与嵌套范围内的模型绑定
- 如何使用D3生成特定范围内的随机颜色
- 将自定义css保持在角度范围内
- Angular JS-文本框未在独立范围内更新
- cookie不在网站范围内
- 获取给定JavaScript范围内的解析函数
- 如何在JavaScript中使用此函数对范围内的所有数字求和
- JavaScript-仅验证数值并且在范围内
- JS:从数组中查找特定范围内的最低/最高数字
- 试图检查表单中的值是否为一个设定范围内的数字
- 在十进制范围内搜索
- 基于日期范围的一组日期范围内的天数
- 如果指令包含在另一个指令中,我如何在隔离范围内添加双向数据绑定属性
- 隔离范围-仅在指令范围内定义的值必须执行更改
- 指令内的角度形式,具有隔离范围
- &操作员未在指令的隔离范围内工作
- AngularJS:在隔离范围内获取属性定义指令的值
- 在角隔离范围内观察表单验证
- 指令隔离范围内的局部数据