We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AngularJS是当前非常的流行的前端框架,它的语法糖非常多,也极大的方便了前端开发者,但是有着用法还是需要去琢磨一下的
#ng-options 在select表单控件中,总结一下目前的几种写法。
##普通写法
<select> <option value="test1">test1</option> <option value="test1">test1</option> <option value="test1">test1</option> <option value="test1">test1</option> </select>
优点:简单
缺点:
##使用ng-repeat
ng-repeat是angularJS中非常强大的一个directive,在渲染列表上极大的方便了前端开发者,那么由于有多个重复的option,当然可以使用ng-repeat,用法如下:
<select> <option ng-repeat="option in options" value="{{option}}">{{option.name}}</option> </select> <script> $scope.options = [{id:1,name:'test1'},{id:2,name:'test2'},{id:3,name:'test3'}]; </scirpt>
优点:
##使用ng-options
这里使用一个年级、班级的选项来作为例子:即选择年级之后再显示对应的可选班级。
<select ng-model="modal.grade" ng-change="modalChangeGrade()" ng-options="grade.gradeText for grade in modal.grades"> <option value="" disabled>请选择</option> </select> <script> $scope.modal.grades = [ {id:1,gradeText:'初一',classes:[]}, {id:2,gradeText:'初二',classes:[]}, {id:3,gradeText:'高一'},classes:[]]; $scope.modalChangeGrade = function(){ //班级的HTML片段就不在这里写了 $scope.modal.classes = $scope.modal.grade.classes; } </scirpt>
注:
$scope.modal.grade = $scope.modal.grades[2];//高一在数组的位置角标为2
#ng-checked
checkbox和radio是我们经常使用到的表单组件,那么如何使用angularJs简洁方便的获取当前已选择对象呢?
这里只说angularJs的用法:
下面依然以年级和班级为例:
<div ng-repeat="class in grade.classes" ng-click="class.is_checked=!class.is_checked"> <input type="checkbox" value="" ng-checked="class.is_checked"> {{class.id+'班'}} </div>
最后需要查看有哪些checkbox被选中时,只需要遍历$scope.grade.classes数组查看有哪些对象的is_checked属性为true即可。
radio的用法同理。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
#ng-options
在select表单控件中,总结一下目前的几种写法。
##普通写法
优点:简单
缺点:
##使用ng-repeat
ng-repeat是angularJS中非常强大的一个directive,在渲染列表上极大的方便了前端开发者,那么由于有多个重复的option,当然可以使用ng-repeat,用法如下:
优点:
缺点:
##使用ng-options
这里使用一个年级、班级的选项来作为例子:即选择年级之后再显示对应的可选班级。
注:
优点:
#ng-checked
checkbox和radio是我们经常使用到的表单组件,那么如何使用angularJs简洁方便的获取当前已选择对象呢?
这里只说angularJs的用法:
下面依然以年级和班级为例:
最后需要查看有哪些checkbox被选中时,只需要遍历$scope.grade.classes数组查看有哪些对象的is_checked属性为true即可。
radio的用法同理。
The text was updated successfully, but these errors were encountered: