0
我很難嘗試使用Angular實現動態加載的內容...我有幾個小部件,他們的partialName
變量通過綁定加載後,請求。這就是爲什麼我在下面使用scope.$watch
。即使模板設置了正確的內容,視圖本身也不會刷新以顯示適當的內容。我嘗試了一些像下面的$broadcast
一樣的東西,但沒有運氣。我怎樣才能做到這一點?謝謝!如何使用AngularJS加載動態指令內容?
export class CioTemplateLoader implements ng.IDirective {
public template: string;
public partials: { [id: string]: string; } = {};
public scope = {
partialName: '='
};
public route: any;
static $inject = [
'$route'
];
constructor(){//$route: any) {
// this.route = $route;
this.partials['claimOverview'] = require('../../claims/claim-overview.html');
//...
}
link = (scope: ng.IScope, elem: JQuery, attributes: ng.IAttributes) => {
var that = this;
scope.$watch('partialName', function (value: string) {
if (value) {
that.template = that.partials[value];
debugger;
scope.$broadcast("REFRESH");
}
});
}
public static Factory(): angular.IDirectiveFactory {
var directive =() => {
return new CioTemplateLoader();
};
return directive;
}
}
謝謝,我要檢查並找回你。 – eestein
你是對的,那是答案,這可以被標記爲重複[我剛剛那樣做]。謝謝! – eestein