Javascript 当我在angular中导入formsmodule时,我的按钮在此之后似乎不起作用
当我在angular项目上从“@angular/forms”;”导入此“import{FormsModule}”时。我的按钮好像不起作用了。如果我点击它,什么都没有 这是我的app.module.tsJavascript 当我在angular中导入formsmodule时,我的按钮在此之后似乎不起作用,javascript,angular,Javascript,Angular,当我在angular项目上从“@angular/forms”;”导入此“import{FormsModule}”时。我的按钮好像不起作用了。如果我点击它,什么都没有 这是我的app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; i
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这是我的家
按钮类是btn
<div class="container color-dark">
<div class="col">
<p>Add you Bucket List</p>
</div>
<div class="col">
<p>Your Bucket List ({{ itemCount }})</p>
</div>
</div>
<div class="container color-light">
<div class="col">
<p>Use this form to add a new Bucket List!</p>
<form>
<input type="text" class="txt" name="item" placeholder="Life Goal.." [(ngModel)]="goalText">
<input type="submit" class="btn" value="Add Item" (click)="addItem()">
</form>
</div>
<div class="col">
<p class="life.container">
I want to climb a mountain.
</p>
</div>
</div>
我试着在谷歌上搜索,但没有弹出任何信息,或者我只是在看代码的错误一面。如果您有什么想法或技巧可以帮助我解决这个问题,我将非常感谢您在home.components.ts中将函数名从additem()更正为
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
itemCount: number;
btnText: string = 'Add an Item';
goalText: string = 'My First Life Goal';
goals = [];
constructor() { }
ngOnInit() {
this.itemCount = this.goals.length;
}
additem(){
this.goals.push(this.goalText);
this.goalText = '';
this.itemCount = this.goals.length;
}
}