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