我有一个警卫,检查状态是否有令牌.
canActivate(): boolean {
const token = this.store.selectSnapshot((state: AuthenticationState) => state.token);
if (!token) {
return true;
}
this.router.navigate(['home']);
return false;
}
Run Code Online (Sandbox Code Playgroud)
然后我有这样的事情:
export class AuthenticationState {
@Selector()
static token(state: AuthenticationStateModel) {
return state.token;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误.'AuthenticationState'类型上不存在属性'token'
假设我想在 monorepo 中的特定包中安装一个包,如何从 root 执行此操作?
在 npm 中,你可以使用如下方法来做到这一点:
npm install react --workspace=a
Run Code Online (Sandbox Code Playgroud)
我搜索了文档,但找不到在 pnpm 中执行此操作的方法。
我想要做的是订阅一个调度,然后调度到另一个状态。我试过 useEffect 但它给了我无限循环和一些谷歌搜索说不要更新 useEffect 的状态所以现在我的代码看起来像这样,但它没有按预期工作。
const Chain = () => {
const [fooState, fooDispatch] = fooOne() // useReducer
const [barState, barDispatch] = barTwo() // useReducer
const btnOnClick = () => {
fooDispatch({ type: "UPDATE_FOO" })
// Update barState base on the new value of foo, doesn't work.
// Foo is not yet updated.
if (fooState.value == 'new value') {
barDispatch({ type: "UPDATE_BAR" })
}
// fooState gets updated after this function block.
}
return <Button label="Button" onClick={btnOnClick} />
}
export …Run Code Online (Sandbox Code Playgroud) 我想做这样的事情来注册。
单击注册按钮时,将执行以下操作:
this.store.dispatch(new Register(user))
.subscribe(response => {
localStorage.setItem('token', JSON.stringify(response.token));
let redirectUrl = this.store.dispatch(new RegisterSuccess(response));
if (redirectUrl) {
this.router.navigate([redirectUrl]);
} else {
this.router.navigate(['/home']);
}
}, error => {
this.store.dispatch(new RegisterFailed());
});
Run Code Online (Sandbox Code Playgroud)
州:
@Action(Register)
register({ patchState }: StateContext<AuthenticationStateModel>, { payload }: Register) {
patchState({
isLoading: true
});
return this.authenticationService.register(payload);
}
@Action(RegisterFailed)
registerFailed({ patchState }: StateContext<AuthenticationStateModel>) {
patchState({
isLoading: false
});
}
@Action(RegisterSuccess)
registerSuccess(sc: StateContext<AuthenticationStateModel>, { payload }: RegisterSuccess) {
sc.patchState({
user: payload.user,
token: payload.token,
isAuthenticated: true,
isLoading: false,
});
return sc.getState().redirectUrl;
} …Run Code Online (Sandbox Code Playgroud) 所以我有一个string []变量,我想只获取特定键的值.
例如我的字符串[]包含
{'firstname': 'john', 'lastname':'doe'}
Run Code Online (Sandbox Code Playgroud)
在我看来,我只想显示姓氏.我该怎么做?
{{myString.lastname}}
Run Code Online (Sandbox Code Playgroud)
给我空白.
{{myString}}
Run Code Online (Sandbox Code Playgroud)
告诉我
{'firstname': 'john', 'lastname':'doe'}
Run Code Online (Sandbox Code Playgroud) 我有Groups,Users,GroupPositions,table.
关系:
用户所属的ToMany Groups
Users areToMany GroupPositions
Group hasMany GroupPositions
//users
public function groupPositions() {
return $this->belongsToMany(
'App\Models\GroupPositionView',
'vw_group_members',
'userId',
'groupPositionId');
}
public function groups() {
return $this->belongsToMany(
'App\Models\GroupView',
'vw_group_members',
'userId',
'groupId');
}
Run Code Online (Sandbox Code Playgroud)
我需要选择一个组,其中包含成员及其在该特定组中的相应位置.成员可以是具有不同职位的不同组的一部分.他可以成为一个团队的领导者,也可以是不同团队的经理.
目前,我有这个查询:
$group = GroupView::where('tag', $tag)
->with(['user.groupPositions'])
->get();
Run Code Online (Sandbox Code Playgroud)
它给了我所有成员的所有成员的所有职位.我想将其过滤到特定的组.
我也有这个:
$groupId = 1;
$group = GroupView::with(['users.groupPositions' => function($query) use($groupId) {
$query->whereHas('group', function($query) use($groupId) {
$query->where('groupId', $groupId);
});
}])
->where('groupId', $groupId)
->firstOrFail();
Run Code Online (Sandbox Code Playgroud)
这个工作.但是,问题是我需要通过标签获取组.如果我将所有groupId更改为tag,则它不再起作用.可能是因为groupPositions和我的vw_group_members没有标记列.
所以我的问题是,是否可以通过标签过滤我的查询?
angular ×3
ngxs ×2
angular5 ×1
eloquent ×1
javascript ×1
laravel ×1
monorepo ×1
node.js ×1
php ×1
pnpm ×1
react-hooks ×1
reactjs ×1
state ×1
store ×1
typescript ×1