angular面试记忆的内容

1.ng-class的用法:ng-class="{red:true}";

2.ng-repeat怎么可以添加重复数据。ng-repeat="item in arr track by $index"

3.ng添加事件的方法。

(1)在directive中,在link函数中,利用第二个参数,el,这是个jquery对象。

(2)在页面的元素上直接添加ng-click="fun($event)",利用传入的$event。

        angular.element(event.target).html('切换状态为:' + $scope.status);

4.ng中$开头的

服务

$scope,$element,$attrs,$transclude

$rootScope,$location ,$http,$timeout

验证阶段需要的属性。

$valid  $dirty  $touched

方法

5.自定义服务。

app.service('hexafy', function() {
	this.myFunc = function (x) {
        return x.toString(16);
    }
});
app.controller('myCtrl', function($scope, hexafy) {
  $scope.hex = hexafy.myFunc(255);
});

5.5 我们比较一下factory与service的区别。factory可以返回任何类型,service只能返回对象。上边的例子,默认返回的this.(这个是我自己理解的)

6.ng中你常用的方法有。

7.ng中controller中你可以传入的参数。$scope,$element,$attrs,$transclude(这个不常用)

8.ng中link你可以传入的参数。

9.ng中的表单验证,错误或者修改的验证,我随后找代码补充。$valid  $dirty  $touched

input属性:
name
ng-model
ng-required
ng-minlength
ng-maxlength
ng-pattern
ng-change值变化时的回调

{{myForm.username.$error}}

Form控制变量
字段是否未更改
formName.inputFieldName.$pristine
字段是否更改
formName.inputFieldName.$dirty
字段有效
formName.inputFieldName.$valid
字段无效
formName.inputFieldName.$invalid
字段错误信息
formName.inputfieldName.$error

10.ng动画简单的。

<script>
var app = angular.module('myApp', ['ngAnimate']);
</script>
过渡的简单的:
div {
    transition: all linear 0.5s;
   
    height: 100px;
}
.ng-hide {
    height: 0;
}
------------
animations
@keyframes myChange {
    from {
        height: 100px;
    } to {
        height: 0;
    }
}
div {
    height: 100px;
   
}
div.ng-hide {
    animation: 0.5s myChange;
}
11.ng-include这个不能跨域,如果跨域的话需要添加。
var app = angular.module('myApp', []) app.config(function($sceDelegateProvider) {
   $sceDelegateProvider.resourceUrlWhitelist([ 'http://c.runoob.com/runoobtest/**' ]);
});
 
12.ng的下路框的ng-options与ng-repeat;
<option ng-repeat="x in sites" value="{{x.url}}">{{x.site}}</option>
<select ng-model="selectedSite" ng-options="x.site for x in sites">
ng-options="x for (x, y) in sites" 
ng-options遍历对象更容易些。
13.angular2
AngularJS2 发布于2016年9月份,它是基于ES6来开发的。
原文地址:https://www.cnblogs.com/coding4/p/6529761.html