简体   繁体   English

如何在 Angular 2 指令的选项元素中获取绑定到 ngValue 的值

[英]How to get values bound to ngValue in option element in an Angular 2 directive

I'm writing a directive in which I need to examine the value used with ngValue in option element.我正在编写一个指令,我需要在其中检查选项元素中与 ngValue 一起使用的值。 The directive sits on the parent.该指令位于父级。 So, if I have the following HTML, is there a way to get to item inside directive validatable ?那么,如果我有以下 HTML,有没有办法进入指令validatableitem

<select [validatable]="trigger" [func]="foo.bind(this)">
    <option *ngFor="let item of items" [ngValue]="item">{{item.s}}</option>
</select>

Thank you in advance.先感谢您。

you seem to be talking angularJS.你似乎在说 angularJS。 I don't think "directive" & "ngValue" are part of angular 2. And not exactly sure what you mean by "item inside directive validatable".我不认为“指令”和“ngValue”是 angular 2 的一部分。并且不完全确定“指令中的项目可验证”是什么意思。

Maybe try something like this?也许尝试这样的事情?

<select (change)="validateItem($event.target.value)">
  <option *ngFor="let item of items" [selected]="item.s == selectedItem">{{item.s}}</option>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ngValue从select&gt; option获取数据 - How to get data from a select>option with ngValue 如何使用角度2生成ngvalue中的两个值? - how to generate the two values in ngvalue using angular 2? Angular 4 ngValue除了给定值以外的所有值 - Angular 4 ngValue everything but given values 选择选项 Angular 4,ngValue 不起作用 - Selected option Angular 4, ngValue don't work 如何在 Angular 指令中获取元素的当前类 - How to get the current classes of an element in an Angular directive 如何在Angular 4中使用Directive和ngModel获取值 - How to get values with Directive & ngModel with Angular 4 Pre select select 标签中的一个选项具有 angular 反应形式的 ngValue - Pre select an option in select tag having ngValue in angular reactive form 角度-以[ngValue] [(ngModel)]为对象预选择选择选项 - Angular - pre-select a select option with [ngValue] [(ngModel)] being objects 使用[ngValue]时,角度选择元素会失去默认值 - Angular select element looses default value when using [ngValue] 在 Angular 2+ 中,如果原生元素也应用了 Angular 指令,你如何指定它应该绑定到模板变量? - In Angular 2+, how do you specify that the native element should be bound to the template variable if it also has an Angular directive applied to it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM