Angularjs 角度隔离作用域在链接功能中不起作用
HTML代码Angularjs 角度隔离作用域在链接功能中不起作用,angularjs,angularjs-directive,Angularjs,Angularjs Directive,HTML代码 <grid-table table-rows="educationBoards"></grid-table> 角度指令 angular.directive('gridTable', functions(){ restrict: 'E', scope: {rows: '=tableRows'}; link: function(scope){ console.log(scope.rows); // shows undefined
<grid-table table-rows="educationBoards"></grid-table>
角度指令
angular.directive('gridTable', functions(){
restrict: 'E',
scope: {rows: '=tableRows'};
link: function(scope){
console.log(scope.rows); // shows undefined
}
})
指令隔离作用域在链接函数中不起作用。为什么???这里有很多问题 首先,控制器中的对象定义错误:
$scope.educationBoards = [{eid = 1, ename = "dhaka"}];
angular.directive('gridTable', functions(){
应该是:
$scope.educationBoards = [{eid : 1, ename : "dhaka"}];
angular.directive('gridTable', function(){
其次,您的功能定义错误:
$scope.educationBoards = [{eid = 1, ename = "dhaka"}];
angular.directive('gridTable', functions(){
应该是:
$scope.educationBoards = [{eid : 1, ename : "dhaka"}];
angular.directive('gridTable', function(){
第三,在指令对象的中间有一个半冒号而不是逗号:
scope: {rows: '=tableRows'}:
应该是:
scope: {rows: '=tableRows'},
angular.directive('gridTable', function(){
return {
restrict: 'E',
scope: {rows: '=tableRows'},
link: function(scope){
console.log(scope.rows);
}
};
})
第四,您需要从指令返回对象,因此:
angular.directive('gridTable', functions(){
restrict: 'E',
scope: {rows: '=tableRows'};
link: function(scope){
console.log(scope.rows); // shows undefined
}
})
应该是:
scope: {rows: '=tableRows'},
angular.directive('gridTable', function(){
return {
restrict: 'E',
scope: {rows: '=tableRows'},
link: function(scope){
console.log(scope.rows);
}
};
})
现在它将起作用。这是一把小提琴:我看到它在小提琴上工作。但它在我的指令中不起作用。这里是github链接:看看你是否能找到它丢失的地方。