【发布时间】:2018-05-19 05:00:50
【问题描述】:
我通过用户点击在模板内动态附加元素,这样:
this.optionValue = [];
youClickMe(){
var moreput = '';
moreput += '<select">';
moreput += '<option *ngFor="let lup of optionValue">{{lup.name}}</option>';
moreput += '</select>';
var pElement = document.querySelector('.somewhereyoubelong');
pElement.insertAdjacentHTML('beforeend', moreput);
}
但是 {{lup.name}} 不会打印实际值,而是在其中键入它的方式。如何使它起作用?有人吗?
更新:
这种方式我试过了,但还是有人说
const templating = '<p *ngFor="let sizeCat of sizeCategoryBySubCategory" [value]="sizeCat.id">{{sizeCat.name}}</p>';
const tmpCmp = Component({template: templating})(class {});
const tmpModule = NgModule({declarations: [tmpCmp]})(class {});
this._compiler.compileModuleAndAllComponentsAsync(tmpModule).then((factories) => {
const f = factories.componentFactories[0];
const cmpRef = f.create(this._injector, [], null, this._m);
//cmpRef.instance.testText = 'B component';
cmpRef.instance.sizeCategoryBySubCategory = [
{ id:1, name: 'a'},
{ id:2, name: 'b'},
];
this._container.insert(cmpRef.hostView);
});
Property binding ngForOf not used by any directive on an embedded template
【问题讨论】:
-
请不要这样做。我想知道你写这样的代码为什么需要这个框架
-
@yurzui,我正在这样做。应该如何,如何解决问题?非常感谢。
-
这部分是独一无二的,所以其实和framework关系不大。该框架的真正目的是为了散列。
标签: angular typescript