угловой - как использовать строку @Input для селектора? - PullRequest
0 голосов
/ 10 июля 2019

Я хочу использовать строку '@Input ()' для селектора, но не могу, селектор всегда регистрирует неопределенный журнал, вот мои примеры:

Конкретный пример

/ ********* файл compA ********* /

// compA -> html (call compB 3 times, every time keying in the different string in [expName])
<compB [expName]="'dog'">
  this is dog //ng-content
</compB>

<compB [expName]="'cat'">
  this is cat //ng-content
</compB>

<compB [expName]="'bird'">
  this is bird //ng-content
</compB>

// compA -> TS
... there is no need, I type string in the html

/ ********* Файл compB (это шаблон) ********* /

// compB -> html
<div #{{expName}}>
    <ng-content></ng-content>
<div>

// compB -> TS
@Input() expName; // when compA using compB, he will type something string to [expName], and compB can read it from @Input.
...

@ViewChild('dog') dog;
@ViewChild('cat') cat;
@ViewChild('bird') bird;

во много Ввод, comA введите собаку 、 кошку ... птицу ... в [expName] comB, так что comB использует @Input, поймите, я смотрю, может быть, [expName] теперь может быть #cat 、 # собака 、 # птица в html.

ngOnInit(){
    console.log( this.dog );
}

теперь я пытаюсь войти #dog, и мне не удалось

...