本地变量的可能性是什么?

3

我想知道本地变量有哪些可能性。我知道以下内容:

  1. You can get a value

    <select #selectField (change)="funtionBla(selectField.value)" 
       <option value="1">1</option>
       <option value="2">2</option>
    </select>
    
  2. You can call methodes of directives

     <button type="button" (click)="directiveBla.myFunction()"> test </button>
    
或基于HTML
<video #movieplayer ...>
  <button (click)="movieplayer.play()">
</video>

但是有没有一种方法可以通过本地变量更改元素的样式,或者将一个元素附加到一个引用元素上?


对我来说看起来不太相似。 - Günter Zöchbauer
ngStylesngClass可以利用变量/属性来决定它们是否被应用。请参见https://angular.io/docs/ts/latest/api/common/NgStyle-directive.html#!#sts=ng-style%20bound%20to%20NgStyle.rawStyle和https://angular.io/docs/ts/latest/api/common/NgClass-directive.html,至于第二个答案,我不确定我理解你想做什么,对我来说,你需要做的是创建一个组件并在内部重复使用它,而不是附加一个引用的组件。 - Langley
1个回答

2

您可以通过本地变量获取元素的引用,例如:

@ViewChild('selectField') someField;

它还用于 DynamicComponentLoader.loadIntoLocation

dcl.loadIntoLocation(DynamicElement, _elementRef, 'selectedField')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接