我無法訪問我將它傳遞給我的指令的對象。爲什麼在指令標籤內傳遞對象時我得到字符串
// inside dialogController
showAlert(ev) {
this.mdDialog.show({
template:"<loader my-master="+this.masterCtrl+"></loader>"
});
// when debugging, I saw this.masterCtrl is exist as Object
//inside loader Controller:
export function loader() {
'ngInject';
let directive = {
templateUrl: "app/components/excelLoader/loader.html",
controller: loaderController,
controllerAs: 'vm',
scope: {
words: '=',
master:'=myMaster'
},
replace: true,
bindToController: true,
link: linkFunc
};
function linkFunc(scope, element, attr, ctrl) {
let vm = scope.vm;
ctrl.master=attr.myMaster;
}
return directive;
}
class loaderController {
constructor() {
'ngInject';
console.log(this.master); //prints string "this.masterCtrl" instead of the Object!
}
}
什麼是從dialogController傳遞this.masterCtrl到loader指令以及如何使用它在loader指令中訪問它的正確方法?
更改' 「+ this.masterCtrl +」''以 「this.masterCtrl」'。 –
@camden_kid它仍然不起作用,它通過「this.masterCtrl」作爲字符串。我從attr.myMaster拿走它,還有其他地方需要嗎? –
嘗試從作用域作爲scope.master –