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

以自己解决


0
0

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程