select if 内的模型值未定义按钮
select button ng model value undefined inside ng if
我有一个问题,我无法从 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 时的结果
需要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>
我有一个问题,我无法从 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 时的结果
需要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>