强类型无法在商店中订阅

时间:2019-01-25 06:57:54

标签: typescript sublimetext3 typescript-typings angular7

我正在使用Sublimetext 3在应用中运行angular 7,我期望模型中的autofill。但是我仍然从对象节点键入了错误的消息,错误根本没有解决。我需要添加任何插件或我的代码有问题吗?

产品状态界面:

import { Product } from "./../product";
import * as fromRoot from "./../../state/app.state";

export interface State extends fromRoot.State {
    products:ProductState
}

export interface ProductState {
    showProductCode : boolean;
    currentProduct : Product;
    products:Product[]
}

这是我的代码:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Store, select } from '@ngrx/store';

import { Subscription } from 'rxjs';

import { Product } from '../product';
import * as fromProduct from  './../state/product.reducer';
import { ProductService } from '../product.service';

@Component({
  selector: 'pm-product-list',
  templateUrl: './product-list.component.html',
  styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit, OnDestroy {
  pageTitle = 'Products';
  errorMessage: string;

  displayCode: boolean;

  products: Product[];

  // Used to highlight the selected product in the list
  selectedProduct: Product | null;
  sub: Subscription;

  constructor(private store:Store<fromProduct.State>, private productService: ProductService) { }

  ngOnInit(): void {

    this.store.pipe(select('products')).subscribe((products) => {
      if(products){
        this.displayCode = products.xxx; //there is no xxx exist at all, no error, require auto fill here.

      }
    })
  }


}

0 个答案:

没有答案