AngularJS实例,Angular,AngularJS 在线

710AngularJS 模型

  • ng-valid: 验证通过
  • ng-invalid: 验证失败
  • ng-valid-[key]: 由$setValidity添加的所有验证通过的值
  • ng-invalid-[key]: 由$setValidity添加的所有验证失败的值
  • ng-pristine: 控件为初始状态
  • ng-dirty: 控件输入值已变更
  • ng-touched: 控件已失去焦点
  • ng-untouched: 控件未失去焦点
  • ng-pending: 任何为满足$asyncValidators的情况

709AngularJS 模型

ng-invalid:未通过验证的表单

ng-valid:布尔型属性,它指示表单是否通过验证。如果表单当前通过验证,他将为true

ng-dirty:布尔值属性,表示用户是否修改了表单。如果为 ture,表示有修改过;false 表示修没有修改过

ng-touched:布尔值属性,表示用户是否和控件进行过交互

ng-pristine:布尔值属性,表示用户是否修改了表单。如果为ture,表示没有修改过;false表示修改过

708AngularJS 指令

还有指令配置项的:link controller等在项目运用中有遇到过:

angular.module('myApp', []).directive('first', [ function(){
    return {
        // scope: false, // 默认值,共享父级作用域
        // controller: function($scope, $element, $attrs, $transclude) {},
        restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
        template: 'first name:{{name}}',
    };
}]).directive('second', [ function(){
    return {
        scope: true, // 继承父级作用域并创建指令自己的作用域
        // controller: function($scope, $element, $attrs, $transclude) {},
        restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
        //当修改这里的name时,second会在自己的作用域中新建一个name变量,与父级作用域中的
        // name相对独立,所以再修改父级中的name对second中的name就不会有影响了
        template: 'second name:{{name}}',
    };
}]).directive('third', [ function(){
    return {
        scope: {}, // 创建指令自己的独立作用域,与父级毫无关系
        // controller: function($scope, $element, $attrs, $transclude) {},
        restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment
        template: 'third name:{{name}}',
    };
}])
.controller('DirectiveController', ['$scope', function($scope){
    $scope.name="mike";
}]);

707AngularJS 指令

angular自定义指令的两种写法:

上面这种,感觉更清晰明确一点。

// angular.module('MyApp',[])
// .directive('zl1',zl1)
// .controller('con1',['$scope',func1]);
//
// function zl1(){
//   var directive={
//     restrict:'AEC',
//     template:'this is the it-first directive',
//   };
//   return directive;
// };
//
// function func1($scope){
//   $scope.name="alice";
// }

//这是教程里类似的写法
angular.module('myApp',[]).directive('zl1',[ function(){
  return {
    restrict:'AE',
    template:'thirective',
    link:function($scope,elm,attr,controller){
      console.log("这是link");
    },
    controller:function($scope,$element,$attrs){
      console.log("这是con");
    }
  };
}]).controller('Con1',['$scope',function($scope){
  $scope.name="aliceqqq";
}]);

706AngularJS 表达式

回复上面的例子:一个页面多个ng-app时

// 页面加载完成后,再加载模块
angular.element(document).ready(function() {
//手动加载myApp2 ng-app
angular.bootstrap(document.getElementById("myApp2"), ['myApp2'])
}) 

才能加载出来