gpt4 book ai didi

javascript - 选择按钮 ng 模型值在 ng 内未定义 if

转载 作者:行者123 更新时间:2023-12-03 03:02:14 25 4
gpt4 key购买 nike

我有一个问题,我无法从 ng-if 内的 ng-model 获取值。如果我警告模型,结果是未定义的。这是我的 html 文件

<div class="col-sm-2">
<select class="form-control" ng-model="yayaya">
<option value="1">yeyeyeye</option>

</select>
</div>
<div class="col-sm-2" ng-if="yayaya ==='1'">
<select class="form-control" ng-model="yoyoyo">
<option value="bla">blabla</option>
</select>
</div>

这是我向 ng-model 发出警报时的结果 when i alert($scope.yayaya); when i alert($scope.yoyoyo);

最佳答案

您需要ng-change来获取模型值,您可以按如下方式传递它,

演示

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
$scope.show = function(yo) {
alert(yo);
}

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<div class="col-sm-2">
<select class="form-control" ng-model="yayaya">
<option value="1">yeyeyeye</option>

</select>
</div>
<div class="col-sm-2" ng-if="yayaya ==='1'">
<select ng-change="show(yoyoyo)" class="form-control" ng-model="yoyoyo">
<option value="bla">blabla</option>
</select>
</div>
</body>

关于javascript - 选择按钮 ng 模型值在 ng 内未定义 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47321329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com