我有这个指令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
(复选框),但由于它是里面被转换的内容,它有一个单独的范围(它是{{{ 1}}的范围和agreementDialog
范围的兄弟姐妹)。访问它的最佳方式是什么?
答案 0 :(得分:1)
ng-model="smth.variableInTranscludedChildScope"
controller: function ($scope) {
$scope.smth = {};
// you can access $scope.smth.variableInTranscludedChildScope here
}