Angular 学习笔记——service &constant
2015-12-09 00:44
666 查看
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="angular.min.js"></script> <script> var m1 = angular.module('myApp',[]); m1.service('myService',FnService); function FnService(){ this.name = 'hello' } FnService.prototype.age = 20; m1.controller('Aaa',['$scope','myService',function($scope,myService){ console.log(myService.name); }]) </script> </head> <body> <div ng-controller="Aaa"> </div> </body> </html>
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="angular.min.js"></script> <script> var m1 = angular.module('myApp',[]); // m1.service('myService',FnService); // function FnService(){ // this.name = 'hello' // } // FnService.prototype.age = 20; m1.constant('myService','hello angular11'); m1.config(['myService',function(myService){ console.log(myService); }]) m1.controller('Aaa',['$scope','myService',function($scope,myService){ console.log(myService); }]) </script> </head> <body> <div ng-controller="Aaa"> </div> </body> </html>
相关文章推荐
- Angular 学习笔记——模块之间的通讯
- part 2 Angular modules and controllers
- AngularJS实现表单手动验证和表单自动验证
- angularjs实现url权限控制
- 学习 AngularJS (五) scope
- AngularJS 指令
- 什么是AngularJS
- angularJs中的隐藏和显示
- 浅谈AngularJS的$parse服务 这篇可以让你看明白
- AngularJs的简单理解和案例
- Angular的侦察兵:$watch()和$observe()
- angular源码分析:$compile服务——指令的编写
- AngularJS是什么
- 一招制敌 - 玩转 AngularJS 指令的 Scope (作用域)
- 如何在AngularJS中消除闪烁
- AngularJS Or jQuery 省份城市二级联动下拉功能
- 开发备忘:AngularJS Syntax error, unrecognized expression in template file
- 【Angularjs】ng-repeat中使用ng-model遇到的问题
- AngularJS Documents 官方英文文档
- AngularJS Documents 官方英文文档