Bon*_*omi 3 typescript angular
将字符串参数添加到类中的构造函数后,浏览器出现错误:
我的课程定义如下:
import { Component, OnInit } from '@angular/core';
import { MatrixComponent } from '../matrix/matrix.component';
@Component({
selector: 'app-player',
templateUrl: './player.component.html',
styleUrls: ['./player.component.css']
})
export class PlayerComponent implements OnInit {
private userName: string;
constructor(private name: string) {
this.userName = name;
this.discovered = 0;
this.matrix = new MatrixComponent();
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
我在另一个类的构造函数中创建对象:
var player1 = new PlayerComponent("Me");
Run Code Online (Sandbox Code Playgroud)
我认为可以在构造函数中传递参数吗?我的代码有什么问题?
| 归档时间: |
|
| 查看次数: |
4353 次 |
| 最近记录: |