小编Ben*_*Ben的帖子

启用/禁用表单控件触发valueChanges Angular 2表单

任何想法为什么在运行以下代码时我得到控制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.

我错过了什么吗?

angular2-forms angular

18
推荐指数
3
解决办法
1万
查看次数

角度模板 - 内联表达式与调用函数

这两者之间有什么区别:

<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)

javascript angular angular5

13
推荐指数
2
解决办法
1665
查看次数

角度路由器以编程方式导航时,旧组件保留在dom中

角度版本: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)

angular2-routing angular angular-router

6
推荐指数
2
解决办法
2245
查看次数

React 钩子和功能组件参考

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)
  1. Comp1 和 Comp2 参考之间有什么区别?
  2. 为什么我必须使用 forwardRef 和 useImperativeHandle 才能真正获得 Comp1 的引用?

https://codepen.io/benma/pen/mddEWjP?editors=1112

reactjs react-ref react-hooks

4
推荐指数
1
解决办法
1万
查看次数