我用angular8构建了一个简单的应用程序,当我对我的component.ts使用模型时遇到了这个错误。我不知道为什么会这样。任何人都可以帮助我解决这个问题?任何错误消息。但是当我在浏览器上运行它时,它在下面显示错误消息
./src/app/test-form/test-form.component.ts 7:70
Module parse failed: Invalid number (7:70)
You may need an appropriate loader to handle this file type.
| constructor() {
| this.topics = ['Angular', 'React', 'Vue'];
> this.userModel = new User('galih', 'galihindra650@gmail.com', 082312514, '', 'morning', true);
| }
| ngOnInit() {
这是我的组件代码
import { User } from '../model/user';
@Component({
selector: 'app-test-form',
templateUrl: './test-form.component.html',
styleUrls: ['./test-form.component.css']
})
export class TestFormComponent implements OnInit {
topics = ['Angular', 'React', 'Vue'];
userModel = new User('galih', 'galihindra650@gmail.com', 082312514, '', 'morning', true);
constructor() { }
ngOnInit() {
}
}
班级用户
export class User {
constructor(
public name: string,
public email: string,
public phone: number,
public topic: string,
public timePreference: string,
public subscribe: boolean
) { }
}
该组件的html
<div class="container-fluid col-6">
<h3>Tes Form</h3>
<form #userForm="ngForm">
{{ userForm.value | json }} <br>User model : {{ userModel|json }}
<!-- <div ngModelGroup="address">
<div class="form-group">
<label>City</label>
<input type="text" required class="form-control" ngModel name="city">
<small class="text-danger">Name is required</small>
</div>
<div class="form-group">
<label> Street</label>
<input type="text" class="form-control" ngModel name="street">
</div>
</div> -->
<!-- Biar value setiam input bisa terbaca harus pake ngModel dan dikasih name -->
<div class="form-group">
<label>Name</label>
<input type="text" required class="form-control" [(ngModel)]="userModel.name" name="name">
<small class="text-danger">Name is required</small>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" [(ngModel)]="userModel.email" name="email">
. . .