Angular面试从喜剧到悲剧的十个问题
1. ng-show/ng-hide 与 ng-if的区别? 2.解释下什么是 step1:Angular解析ng-app然后在内存中创建 step2:angular回继续解析,找到{{}}表达式,并解析成变量。 step3:接着会解析带有ng-controller的div然后指向到某个controller函数。这个时候在这个controller函数变成一个 3. 表达式 {{yourModel}}是如何工作的? 4.Angular中的digest周期是什么? 5.如何取消 var customTimeout = $timeout(function () {
// your code
},1000);
$timeout.cancel(customTimeout);
停掉一个 // .$watch() 会返回一个停止注册的函数
function that we store to a variable
var deregisterWatchFn = $rootScope.$watch(‘someGloballyAvailableProperty’,function (newVal) {
if (newVal) {
// we invoke that deregistration function,to disable the watch
deregisterWatchFn();
...
}
});
6. Angular Directive中restrict 中分别可以怎样设置?scope中@,=,&有什么区别? 1.A匹配属性 当然你可以设置多个值比如AEC,进行多个匹配。 在scope中,@,&在进行值绑定时分别表示 angular.module('docsIsolationExample',[])
.controller('Controller',['$scope',function($scope) {
$scope.alertName = function() {
alert('directive scope &');
}
}])
.directive('myCustomer',function() {
return {
restrict: 'E',scope: {
clickHandle: '&'
},template: '<button ng-click="testClick()">Click Me</button>',controller: function($scope) {
$scope.testClick = function() {
$scope.clickHandle();
}
}
};
});
<div ng-app="docsIsolationExample">
<div ng-controller="Controller">
<my-customer click-handle="alertName()"></my-customer>
</div>
</div>
Codepen Demo 4.< 进行单向绑定。 7. 列出至少三种实现不同模块之间通信方式? 8. 有哪些措施可以改善Angular 性能 myApp.config(function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
});
2、使用一次绑定表达式即{{::yourModel}} console.time("TimerName");
//your code
console.timeEnd("TimerName");
9. 你认为在Angular中使用jQuery好么? 我们不妨再换个角度,如果业务需求,而对于一个新人(比较熟悉jQuery)的话,或许你引入jQuery可以让它在解决问题,比如使用插件上有更多的选择,当然这是通过影响代码组织来提高工作效率,随着对于angular理解的深入,在重构时会逐渐摒弃掉当初引入jquery时的一些代码。 所以我觉得两种框架说完全不能一起用肯定是错的,但是我们还是应该尽力去遵循angular的设计。 10.如何进行angular的单元测试 describe('calculator',function () {
beforeEach(module('calculatorApp'));
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('sum',function () {
it('1 + 1 should equal 2',function () {
var $scope = {};
var controller = $controller('CalculatorController',{ $scope: $scope });
$scope.x = 1;
$scope.y = 2;
$scope.sum();
expect($scope.z).toBe(3);
});
});
});
关于测试,大家可以看下使用karma进行angular测试 除了Karam,Angular.js团队推出了一款e2e(end-to-end)的测试框架protractor 转载自:http://www.52php.cn/article/p-vyzhgxmx-c.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |