How can I pass props down in Angular 2+ like React?

前端 未结 2 1827
别跟我提以往
别跟我提以往 2021-02-13 02:48

In react I can arbitrarily pass props down like so:

function SomeComponent(props) {
  const {takeOutProp, ...restOfProps} = props;
  return 
2条回答
  •  鱼传尺愫
    2021-02-13 03:15

    As opposed to React components, Angular components aren't recompiled on input changes and use @Input property decorators to enable change detection. All properties that are expected to be passed should be explicitly defined as component inputs.

    There are no better options than this one for custom select component. It's possible to read static attributes from current component element and set them on nested component element, but this won't set up bindings.

    As for React recipe for deep props in wrapped components:

    const Baz = props => 

    {props.baz}

    ; const Bar = props => ; const Foo = props => ;

    This is usually handled by Angular DI and a hierarchy of injectors. A provider can be defined on respective injector in order to make data and behaviour available to nested components.

提交回复
热议问题