1、HTML代码如下:
<!-- 这个是街道 -->
<select name="jd" ng-model="wgy.jd" class="form-control input-sm" ng-options="jd.code as jd.label for jd in bmOfJd" ng-change="getSqBm(wgy.jd)">
<option value="">--请选择--</option>
</select>
<!-- 这个是社区 -->
<select name="sq" ng-model="wgy.sq" class="form-control input-sm" ng-options="sq.code as sq.label for sq in bmOfSq">
<option value="">--请选择--</option>
</select>
2、JS代码如下:
//如果选择街道,去取出社区
$scope.getSqBm = function(jd){
BmService.getXzqh(jd)
.then(function(data){
$scope.bmOfSq = data;
});
};
3、问题:因为我这个在新增页和查询页公用,所以当编辑页的时候,我给街道wgy.jd赋值,但是这样是不会触发街道ng-change的,我怎样才能触发ng-change呢?
Thank you for your answers. I have found a way
That is to manually call the ng-change method getSqBm($scope.wgy.jd) after assigning a value to wgy.jd.
This way it will trigger the ng-change of the street! ! !
Here are detailed instructions
It’s better to use watch to do it. Use changes in observed data to trigger a certain method
http://stackoverflow.com/questions/14386570/getting-the-ng-object-selected-with-ng-change
HTML
SCRIPT