Javascript &;操作员不在指令的隔离范围内工作
我正在指令的隔离范围内使用&(表达式绑定)运算符,但无法在父控制器上触发函数。控制台上应该有输出,但我没有收到任何输出 在HTML部分:Javascript &;操作员不在指令的隔离范围内工作,javascript,angularjs,Javascript,Angularjs,我正在指令的隔离范围内使用&(表达式绑定)运算符,但无法在父控制器上触发函数。控制台上应该有输出,但我没有收到任何输出 在HTML部分: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Directive &</title> <script type="text/javascript" src="angul
<!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>
指示&
Ctrl数据
{{person.name}
指令数据
下面是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:"&"
}
};
});
角度模块('隔离范围',[])
.controller('isolateScopeController',函数($scope){
$scope.persons=[
{
姓名:“tanmay”,
年龄:"28"
},
{
姓名:“詹姆斯”,
年龄:"28"
},
{
姓名:“赖兰”,
年龄:“26”
},
{
姓名:“Aditya”,
年龄:“23”
}
];
$scope.printScopeToFile=函数(){
log(“打印到文件…”);
用于(风险值i,单位为$scope.persons){
console.log(“Name=“+$scope.persons[i].Name+”Age=“+$scope.persons[i].Age”);
}
};
})
.directive('friends',function(){
返回{
限制:'E',
模板:“”,
范围:{
名称:'=frnd'
}
};
})
.directive('myButton',function(){
返回{
限制:'E',
模板:“callParentfunction”,
范围:{
隔离功能:“&”
}
};
});
同样的:指令中的属性
隔离函数
应该是隔离函数
,属性是的,规范化,我在这方面浪费了很多时间。有人能解释一下为什么规范化首先是在角度上进行的吗。它需要什么?HTML属性不区分大小写,但JavaScript是。@JackSparrow对于规范化,您也可以看一下