我有一个指令agreementDialog,它反过来使用泛型对话框指令myapp-dialog-window-modal
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的作用域的同级变量)。访问它的最佳方式是什么?
发布于 2018-05-04 10:52:53
ng-model="smth.variableInTranscludedChildScope"
controller: function ($scope) {
$scope.smth = {};
// you can access $scope.smth.variableInTranscludedChildScope here
}https://stackoverflow.com/questions/50169306
复制相似问题