我无权访问我在指令中传递的对象。
lazy
将dialog.troller中的this.masterCtrl传递给loader指令以及如何在loader指令中使用它是正确的方法是什么?
答案 0 :(得分:0)
在您的链接功能中,分配ctrl.master = scope.master;
attr.myMaster
将从html标记中读取属性值,并且将是一个字符串。 scope.master
将通过角度进行评估。
答案 1 :(得分:0)
标记
<div ng-controller="MyController as vm" ng-cloak="" ng-app="app">
<md-button class="md-primary md-raised" ng-click="vm.openDialog($event)">
Dialog
</md-button>
</div>
JS
angular.module('app',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('MyController', function($scope, $mdDialog) {
var vm = this;
vm.testObject = {test: "blah"};
vm.openDialog = function(ev) {
$mdDialog.show({
controller: 'DialogController',
controllerAs: 'DialogCtrl',
template: '<loader my-master="vm.testObject"></loader>',
parent: angular.element(document.body),
scope: $scope,
preserveScope: true,
targetEvent: ev,
clickOutsideToClose:true
});
};
})
.controller('DialogController', function($scope, $mdDialog) {
})
.directive("loader", loader);
function loader() {
return {
template: "<div>Loader directive - {{vm.master.test}}</div>",
controller: loaderController,
controllerAs: 'vm',
scope: {
words: '=',
master:'=myMaster'
},
replace: true,
bindToController: true,
};
function loaderController ($scope) {
console.log($scope.vm.master);
}
}