search

Home  >  Q&A  >  body text

javascript - How does angular2 bind input attributes to the component tags that need to be routed to after <route-outlet></route-outlet> takes up space?

Solution, as described in the question,
I want to pass data to a component, but this component is displayed at the location of <route-outlet></route-outlet> and [XX] cannot be added directly to the routeroutlet label. = "XX",

Looking at the documentation, it seems that class and attr can be bound through the host field annotated by @conponent.
But when I bind [input value], an error will be reported,

@Component({
  selector: 'app-onlinecourse',
  templateUrl: './onlinecourse.component.html',
  host:{
    class:"test",
    '[test]':"test"
  }
......

  @Input()
  test;
.....
 ngOnChanges() {
      console.log(this.test);
  }
//undifind

Error message:
Can't bind to 'test' since it isn't a known property of 'app-onlinecourse'.

请输入代码

Thanks

迷茫迷茫2772 days ago616

reply all(1)I'll reply

  • 学习ing

    学习ing2017-06-12 09:27:58

    angular’s ​​host follows the binding rules of template syntax, please refer to (Template Syntax) [https://angular.io/docs/ts/la...

    So, your host should probably look like this:

    host: {
        '[class.special]': 'test',
        '[attr.aria-label]': 'true'
    }

    reply
    0
  • Cancelreply