简体   繁体   English

如何改变 <select> ng-model中的默认值是可以激活ng-change中的功能的更改?

[英]How to make changing a <select>'s default value in ng-model as a change that can activate the function in ng-change?

<select name="BF_base_type" id="BF_base_type" 
style="display:inline height:20px;" 
ng-model="BF_base_type"  
ng-change="activateDiv('Model_BF','BF_base_type')" 
ng-options="start.value as start.name for start in startOptions"> </select>

In above , there is default value ="BF_base_type" for the selection given by ng-model. 在上面,ng-model给定的选择有默认值=“ BF_base_type”。 There is a function for ng-change, which will activate once there is a change happened to the selection. 有一个用于ng-change的功能,一旦选择发生更改,该功能便会激活。

What I wanted to have is to activate ng-change function by checking the default value for the selection specified by ng-model, no matter there is change or not by user interaction. 我想要的是通过检查ng-model指定的选择的默认值来激活ng-change功能,无论是否存在更改,或者用户交互是否存在。

For example. 例如。 By default, BF_base_type is empty or not defined. 默认情况下,BF_base_type为空或未定义。 So is empty. 所以是空的。 Upon user's interaction, BF_base_type will be assigned a non-empty value. 在用户交互后,将为BF_base_type分配一个非空值。 By observation, assigning a non-empty value to BF_base_type would not activate the function associated to ng-change. 通过观察,将非空值分配给BF_base_type不会激活与ng-change相关的功能。

How can I activate the function associated to ng-change for changing the value of the variable (BF_base_type in this case) assigned to ng-model from one (empty or null) to another (non-empty, none)? 如何激活与ng-change相关的功能,以将分配给ng-model的变量(在这种情况下为BF_base_type)的值从一个(空或空)更改为另一个(非空,无)?

Thanks... 谢谢...

Add a ng-init line to trigger it at the beginning: 添加ng-init行以在开始时触发它:

<select name="BF_base_type" id="BF_base_type" 
style="display:inline height:20px;" 
ng-model="BF_base_type"  
ng-change= "activateDiv('Model_BF', BF_base_type)"
ng-init  = "activateDiv('Model_BF', BF_base_type)"
ng-options="start.value as start.name for start in startOptions"> </select>

By the way do you really want the quotes around BF_base_type in your ng-change ? 顺便说一句,您是否真的想要ng-change BF_base_type的引号? If you do so you'll get the string, without them you'll get the value. 如果这样做,您将获得字符串,没有它们,您将获得值。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM