我需要获取自定义指令范围值。 我正在尝试访问函数内的scope.cellId。它不起作用。你能请任何人为此提供解决方案吗?
提前致谢..
这里是 fiddle 链接:
这是一些 Controller :
var bosAppModule = angular.module('testapp', []);
bosAppModule.controller('testCtrlr',['$scope', function($scope){
$scope.layoutData =[ {layouttablecelltableid:"dsafdasfasdf"},{layouttablecelltableid:"aaaaaa"}]
}]);
bosAppModule.directive('layoutTableCellView',function($compile){
var layoutTableCellObj={};
linkFnTableCell=function(scope, element, attributes, controllerCtrl) {
console.log("#####"+scope.cellId);
};
layoutTableCellObj.restrict='AE';
layoutTableCellObj.replace='true';
layoutTableCellObj.scope={layoutData:'=',cellId:'@'};
layoutTableCellObj.template="<div cell-id='tablecell.layouttablecelltableid' style='background-color:grey;height:200px;' layout-data='layoutData' ng-repeat='tablecell in layoutData' >{{tablecell.layouttablecelltableid}}</div>";
layoutTableCellObj.link = linkFnTableCell;
return layoutTableCellObj;
});
这是 HTML:
<div ng-app="testapp">
<div ng-controller="testCtrlr">
<layout-table-cell-view> </layout-table-cell-view>
</div>
</div>
最佳答案
我不确定我是否理解您想要实现的目标。你能提供更多细节吗?我已经清理了你的 fiddle ,因为它有点乱,而且 Angular 没有为我加载:
https://jsfiddle.net/6xLt4pja/1/
指令:
bosAppModule.directive('layoutTableCellView', [
function () {
return {
restrict: 'AE',
template: "<div style='background-color:grey;height:200px;' ng-repeat='tablecell in layoutData'>{{tablecell.layouttablecelltableid}}</div>",
scope: {
layoutData:'='
},
link: function (scope) {
console.log('SCOPE: ', scope.layoutData);
}
};
}
]);
和 html:
<div ng-app="testapp">
<div ng-controller="testCtrlr">
<layout-table-cell-view layout-data="layoutData"></layout-table-cell-view>
</div>
</div>
关于javascript - 客户指令 ng-repeat 作用域未进入 Angular JS 函数内部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37696300/