任何想法为什么在运行以下代码时我得到控制valueChanges事件被'firstName'触发?
let form: FormGroup = this.createForm();
form.controls['firstName'].enable();
form.controls['firstName'].valueChanges(value=>{
//some code
});
Run Code Online (Sandbox Code Playgroud)
由于没有任何价值变化(只是状态),我不希望valueChanges在这里触发,只有statusChanged.
我错过了什么吗?
这两者之间有什么区别:
<li [ngClass]="{disabledField: condition1 && condition2 && condition3}">Click</li>
Run Code Online (Sandbox Code Playgroud)
VS
<li [ngClass]="{disabledField: shouldDisableField()}">Click</li>
Run Code Online (Sandbox Code Playgroud)
在组件类中:
shouldDisableField(): boolean{
return this.condition1 && this.condition2 && this.condition3;
}
Run Code Online (Sandbox Code Playgroud) 角度版本:4
从LoginComponent(位于public/signin路径中)登录后,我想要TestComponent在路径中导航public/test.我这样做如下:this._router.navigate(['public/test'])
然后,它正确地重定向但问题是它不会LoginComponent从DOM中删除(尽管ngOnDestroy会被调用).
值得一提的是,导航到按预期TestComonent使用的
<a routerLink='/public/test'>Test</a>工作.
我究竟做错了什么?
app.routing.ts:
const APP_ROUTES:Routes = [
{path: 'public', loadChildren: './authentication/authentication.module#AuthenticationModule'}
];
export const APP_ROUTING:ModuleWithProviders = RouterModule.forRoot(
APP_ROUTES, {
useHash: false, enableTracing: true, initialNavigation: true});
Run Code Online (Sandbox Code Playgroud)
`authentication.routing.ts(这两个组件都属于):
const routes: Routes = [
{
path: '',
children: [
{path: 'test', component: TestComponent},
{path: 'signin', component: LoginComponent},
]
}
];
export const routing = RouterModule.forChild(routes);
Run Code Online (Sandbox Code Playgroud) const Comp1 = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({
print: () => {
console.log('comp1')
}
}), []);
return <div>comp1</div>
});
const Comp2 = () => <div>comp2</div>;
const App = () => {
const ref1 = useRef(null);
const ref2 = useRef(null);
useEffect(() => {
console.log(ref1); // prints ref1 with the expected current
console.log(ref2); // prints ref2 with current: null
})
return <div><Comp1 ref={ref1}/><Comp2 ref={ref2}/></div>
}
Run Code Online (Sandbox Code Playgroud)