zoukankan      html  css  js  c++  java
  • angularjs笔记

    1. Dom元素设置css为display:none,ng-show绑定无效
      类似这个问题的描述
      解决:初始设置display:none;然后绑定的字段初始设置false,即可实现初始化不显示,又能正常双向绑定。

    2. 使用ng-repeat生成option时select的ng-model绑定问题的整数类型字段不绑定的问题
      原因:option的value是string
      解决:a. 传值时将数值转为string; b. 使用ng-options
      http://blog.csdn.net/u011127019/article/details/54630741

    3. 结合select2控件进行绑定赋值报错的问题
      描述:使用了基于jQuery的select2选择控件,并且使用ng-model进行了绑定,但是给model赋值无法生效。
      解决办法:$timeout(function(){ $('#elment').trigger('change'); })
      注意:这里必须在timeout里执行trigger,否则报错,原因尚不明。

    4. ng-required使用,可以动态调整required

    5. 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>
      
    6. hidden域无法绑定对象

    7. 自定义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();
    });
    
  • 相关阅读:
    function与感叹号
    js中的|| 与 &&
    [转] html屏蔽右键、禁止复制
    ExtJS 5.1 WINDOW BLUR
    ExtJS 网页版执行工具
    Excel 随即获得一组数据集中的数据
    [转] Spring Data JPA Tutorial: Pagination
    Set up eclipse for Ext js and spket IDE plugin
    ExtJS Alias, xtype and widget
    ExtJS stores
  • 原文地址:https://www.cnblogs.com/liqipeng/p/7452691.html
Copyright © 2011-2022 走看看