I have a select tag in html which has a value from angularjs. Everytime I select a value, the select tag will be empty. Why? How to fix it?

我在html中有一个select标签,它有一个来自angularjs的值。每次我选择一个值时,select标签都是空的。为什么?怎么解决?

$scope.getAll = function(){
     $http.post()....
     $scope.places = response.data;
};

$scope.getAll();

$scope.sample = function(str){
   alert(str);
};

HTML

HTML

<select ng-model="val" ng-change="sample(val)">
     <option ng-repeat="place in places" value="place.name">{{place.name}}</option>
</select>

In code above, when I select some value of the select tag it alerts me the value but the select tag goes empty!

在上面的代码中,当我选择select标签的某个值时,它会提醒我值,但select标签变为空!

2 个解决方案

#1


2

i recommend instead of using ng-repeat use ng-options

我建议使用ng-repeat而不是使用ng-repeat

angular.module("app",[])
.controller("ctrl",function($scope){

 $scope.places = [ {name: 'California'},
                          {name: 'New York'},
                          {name: 'Cochin'}
                        ];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <select ng-model="val" ng-change="sample(val)" ng-options="place.name as place.name for place in places">
</select>
{{val}}
</div>

更多相关文章

  1. HTML5绘图之Canvas标签 绘制坐标轴
  2. 如何在execCommand formatBlock 'p'标签中添加类或id或CSS样式?
  3. script标签写在哪里好?
  4. 从动态生成的音频标签中收听audio.ended
  5. 点击a标签,返回上一页
  6. JS实现60s倒计时(亲测有效),及span标签如何使用和禁用onclick事件
  7. 等待执行所有ajax回调的最佳解决方案
  8. FusionCharts的Line.swf做法,我想出现2条图形线,怎么设置graph标签
  9. 如何在chart.js中为饼图添加标签

随机推荐

  1. android粗略获得程序运行时间的方法
  2. Android 获取经纬度。2018年写
  3. Android service通信
  4. imageView动画效果
  5. widget(5、DatePicker)
  6. android 下测试网络的丢包率和延迟 的代
  7. Android APK 文件自动安装
  8. androidd 几个开源框架
  9. Android截屏及图片解析
  10. 实例教程四:采用Pull解析器解析和生成XML