ERROR TypeError: Cannot read property 'indexOf' of undefined
来源:7-10 表单处理实战上
zhouzhao2016
2019-05-11
categories = [“IT”, “互联网”, “金融”];
constructor(private routeInfo:ActivatedRoute, private stockService:StockService,
private router:Router
) { }
ngOnInit() {
let stockId = this.routeInfo.snapshot.params[‘id’];
this.stock = this.stockService.getStock(stockId);
let fb = new FormBuilder();
this.formModel = fb.group(
{
name:[this.stock.name, [Validators.required, Validators.minLength(3)]],
price:[this.stock.price, Validators.required],
desc: [this.stock.desc],
categories: fb.array([
new FormControl(this.stock.categories.indexOf(this.categories[0]) != -1),
new FormControl(this.stock.categories.indexOf(this.categories[1]) != -1),
new FormControl(this.stock.categories.indexOf(this.categories[2]) != -1)
])
}
);
}
写回答
1回答
-
zhouzhao2016
提问者
2019-05-11
以自己解决
00
相似问题