javascript - 客户指令 ng-repeat 作用域未进入 Angular JS 函数内部?

标签 javascript angularjs

我需要获取自定义指令范围值。 我正在尝试访问函数内的scope.cellId。它不起作用。你能请任何人为此提供解决方案吗?

提前致谢..

这里是 fiddle 链接:

http://jsfiddle.net/na8udkkt/

这是一些 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/

相关文章:

javascript - 使用 angular 和 bootstrap 创建一个 "responsive number"指令

javascript - ng-repeat 中按键自定义对象排序

在 href 属性中使用 AngularJS 表达式时 HTML5 验证失败

javascript - 如何在Restangular中添加多个Auth Interceptor?

javascript - mongoose mongodb - 删除所有条件为真的地方,除了一个

javascript - Jquery $.post 成功时的默认函数

javascript - 共享时会显示动画的开放图 Gif

javascript - 单页应用性能问题

javascript - 搜索文件夹结构

javascript - Meteor Iron Router 等待模板渲染