-
Dom元素设置css为display:none,ng-show绑定无效
类似这个问题的描述
解决:初始设置display:none;然后绑定的字段初始设置false,即可实现初始化不显示,又能正常双向绑定。 -
使用ng-repeat生成option时select的ng-model绑定问题的整数类型字段不绑定的问题
原因:option的value是string
解决:a. 传值时将数值转为string; b. 使用ng-options
http://blog.csdn.net/u011127019/article/details/54630741 -
结合select2控件进行绑定赋值报错的问题
描述:使用了基于jQuery的select2选择控件,并且使用ng-model进行了绑定,但是给model赋值无法生效。
解决办法:$timeout(function(){ $('#elment').trigger('change'); })
注意:这里必须在timeout里执行trigger,否则报错,原因尚不明。 -
ng-required使用,可以动态调整required
-
ng-options
数组作为数据源
$scope.sites = [ {site : "Google", url : "http://www.google.com"}, {site : "aa", url : "http://www.aa.com"}, {site : "Taobao", url : "http://www.taobao.com"} ]; <select ng-model="selectedSite" ng-options="x.site for x in sites"> </select> <select ng-model="selectedSite" ng-options="x.url for x in sites"> </select> <select ng-model="selectedSite" ng-options="x.site+', '+x.url for x in sites"> </select>
数据对象作为数据源
$scope.sites = { site01 : "Google", site02 : "aa", site03 : "Taobao" }; //x 为键(key), y 为值(value) <select ng-model="selectedSite" ng-options="x for (x, y) in sites"> </select>
-
hidden域无法绑定对象
-
自定义filter
自定义带参数的过滤器
8.angular.copy实现reset
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.master = {firstName: "John", lastName: "Doe"};
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
});