首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在嵌套AngularJS指令中访问已被屏蔽的子范围

如何在嵌套AngularJS指令中访问已被屏蔽的子范围
EN

Stack Overflow用户
提问于 2018-05-04 07:17:13
回答 1查看 31关注 0票数 0

我有一个指令agreementDialog,它反过来使用泛型对话框指令myapp-dialog-window-modal

代码语言:javascript
复制
angular.module('myapp.common.extra').directive('agreementDialog', function () {

    return {
        restrict: 'E',
        replace: true,
        template: '<div><myapp-dialog-window-modal window-title="Agreements" dialog-visible="agreementDialogVisible">'
                    + '<p>You need to accept the new terms.</p>'
                    + '<p><label><input type="checkbox" ng-model="variableInTranscludedChildScope"/>I accept the agreement</label></p>'
                    + '<p><button ng-click="submitAgreement(didAgree)">Submit</button></p>'
                + '</myapp-dialog-window-modal></div>',

        controller: function ($scope) {

            $scope.submitAgreement = function (didAgreeLocal) {
                console.log(`submitAgreement`, didAgreeLocal);
            };

            $scope.didAgree = false;
            $scope.agreementDialogVisible = true;

        }

    };
});

我需要访问代码中提到的变量variableInTranscludedChildScope (复选框),但是由于它在被屏蔽的内容中,所以它有一个单独的作用域(它是agreementDialog的作用域的子变量,也是myapp-dialog-window-modal的作用域的同级变量)。访问它的最佳方式是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-04 10:52:53

代码语言:javascript
复制
ng-model="smth.variableInTranscludedChildScope"

controller: function ($scope) {
  $scope.smth = {};

  // you can access $scope.smth.variableInTranscludedChildScope here
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50169306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档