<!DOCTYPE HTML>
<html lang="zh-cn" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>basics</title>
<style type="text/css">
.ng-cloak {
display: none;
}
</style>
</head>
<body>
<div class="ng-cloak">
{{'Kitty' | greet}}
</div>
<script src="../angular-1.0.1.js" type="text/javascript"></script>
<script type="text/javascript">
var simpleModule = angular.module("myApp", []);
simpleModule.filter("greet", function () {
return function(name) {
return "Hello " + name + " !";
}
});
</script>
</body>
</html>
angular.module('myModule', []).
config(function(injectables) { // provider-injector
// 这里是config block的一个例子
// 我们可以根据需要,弄N个这样的东东
// 我们可以在这里注入Providers (不是实例,not instances)到config block里面
}).
run(function(injectables) { // instance-injector
// 这里是一个run block的例子
// 我们可以根据需要,弄N个这样的东东
// 我们只能注入实例(instances )(不是Providers)到run block里面
});
angular.module('myModule', []).
value('a', 123).
factory('a', function() { return 123; }).
directive('directiveName', ...).
filter('filterName', ...);
// 等同于
angular.module('myModule', []).
config(function($provide, $compileProvider, $filterProvider) {
$provide.value('a', 123)
$provide.factory('a', function() { return 123; })
$compileProvider.directive('directiveName', ...).
$filterProvider.register('filterName', ...);
});
angular.module('greetMod', []).
factory('alert', function($window) {
return function(text) {
$window.alert(text);
};
})
.value('salutation', 'Hello')
.factory('greet', function(alert, salutation) {
return function(name) {
alert(salutation + ' ' + name + '!');
};
});
describe('myApp', function() {
// 加载应用响应的module,然后加载指定的将$window重写为mock版本的测试module,
// 这样做,当进行window.alert()时,测试器就不会因被真正的alert窗口阻挡而停止
//这里是一个在测试中覆盖配置信息的例子
beforeEach(module('greetMod', function($provide) {//这里看来是要将真正的$window替换为以下的东东
$provide.value('$window', {
alert: jasmine.createSpy('alert')
});
}));
// inject()会创建一个injector,并且注入greet和$window到测试中。
// 测试不需要关心如何写应用,只需要关注如何测试应用。
it('should alert on $window', inject(function(greet, $window) {
greet('World');
expect($window.alert).toHaveBeenCalledWith('Hello World!');
}));
// 这里是在测试中通过行内module和inject方法来覆盖配置的方法
it('should alert using the alert service', function() {
var alertSpy = jasmine.createSpy('alert');
module(function($provide) {
$provide.value('alert', alertSpy);
});
inject(function(greet) {
greet('World');
expect(alertSpy).toHaveBeenCalledWith('Hello World!');
});
});
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有