angular 2 ngrx/存储不可用数据中断异步管道
如果我的初始状态是angular 2 ngrx/存储不可用数据中断异步管道,angular,ngrx,Angular,Ngrx,如果我的初始状态是 export const initialState: State = { release: '', shape: '', story: '', keyFeatures: [''], colors: [] }; export function reducer(state = initialState, action): State { switch(action.type) { case "UPDATE_PRODUCT": retu
export const initialState: State = {
release: '',
shape: '',
story: '',
keyFeatures: [''],
colors: []
};
export function reducer(state = initialState, action): State {
switch(action.type) {
case "UPDATE_PRODUCT": return Object.assign({}, action.payload || state);
case "UPDATE_COLOR":
return Object.assign({}, state, {currentColor: action.payload.currentColor, imagePaths: action.payload.imagePaths})
default:
return state;
}
}
组件正在消耗这样的状态
<img class="glassesImg" [images]="paths | async" >
_store.select('product')
.subscribe((product: State) => {
this.collection = product.collection;
this.release = product.release;
this.sku = product.sku;
this.paths = product.imagePaths;
})
_store.select('产品')
.订阅((产品:状态)=>{
this.collection=product.collection;
this.release=product.release;
this.sku=product.sku;
this.path=product.imagepath;
})
当没有任何可用数据时,我收到错误“管道“AsyncPipe”的参数无效”。我希望AsyncPipe可以订阅“”作为该属性的有效字符串值?我错过了什么 为什么需要具有正常同步值的
async
管道async
需要与Observable
或Promise
一起使用,但是路径
只是一种正常的值类型
如果要使用async
,可以执行以下操作
<something [blah]="(model$ | async)?.someProperty">
class Component {
model$
...
this.model$ = store.select(..)
}
类组件{
模型$
...
this.model$=store.select(..)
}
或者不使用
async
,只使用默认值初始化组件属性,直到第一个值从存储区中输入。我已经尝试了您的建议,但无法像我已经使用的代码那样渲染图像。我也尝试过完全删除异步管道,但没有成功。到底什么是[images]
,为什么要使用img
标记?