Angular2-使用单击事件添加项目
我知道以前有人问过这个问题,但我找到的最好的答案是9个月前的:而且对新产品不起作用 我想用angular2中的简单单击将Angular2-使用单击事件添加项目,angular,onclick,Angular,Onclick,我知道以前有人问过这个问题,但我找到的最好的答案是9个月前的:而且对新产品不起作用 我想用angular2中的简单单击将或任何其他项目推送到我的HTML中 我该怎么做 我想在新的angular中重新创建plunker我想这就是你想要的: import { Component } from '@angular/core'; class ContactInfo { constructor(public description: string) {} } @Component({ sele
或任何其他项目推送到我的HTML中
我该怎么做
我想在新的angular中重新创建plunker我想这就是你想要的:
import { Component } from '@angular/core';
class ContactInfo {
constructor(public description: string) {}
}
@Component({
selector: 'my-app',
template: `
<ul>
<li *ngFor="let info of information">
<pre>{{ info.description }}</pre>
</li>
</ul>
<input #newInfo (keyup.enter)="addInfo(newInfo.value)" (blur)="addInfo(newInfo.value); newInfo.value='' ">
<button (click)="addInfo(newInfo.value)">Add</button>
`
})
export class AppComponent {
information = [
new ContactInfo('HTML5 = Regards DOM'),
new ContactInfo('CSS3 = Regards DOM styling')
];
addInfo(newInfo: string) {
if (newInfo) {
this.information.push(new ContactInfo(newInfo));
}
}
}
从'@angular/core'导入{Component};
类联系人信息{
构造函数(公共描述:字符串){}
}
@组成部分({
选择器:“我的应用程序”,
模板:`
-
{{info.description}}
添加
`
})
导出类AppComponent{
信息=[
新联系人信息('HTML5=DOM'),
新建ContactInfo('CSS3=DOM样式')
];
addInfo(新信息:字符串){
如果(新信息){
this.information.push(newcontactinfo(newInfo));
}
}
}
试试这个:
从'@angular/core'导入{Component};
类联系人信息{
构造函数(公共描述:字符串){}
}
@组成部分({
选择器:“我的应用程序”,
模板:`
-
{{info.description}}
添加
`
})
导出类AppComponent{
信息=[];
myInfo=this.information[0];
addInfo(新信息:字符串){
如果(新信息){
this.information.push(newcontactinfo(newInfo));
}
}
}
请提供有关您正在尝试执行的操作的更多信息,我将帮助您。如果列表项来自数组,只需推送一个新条目。假设我们有一个列表,我想向其中添加一个项目。就这么简单。这既不是代码编写服务,也不是教程服务。给出你的代码的一个例子,展示你到目前为止所取得的成就和它的具体问题。