html5_依赖注入的5个重要的组件
来源:互联网 发布:java如何引用别的类 编辑:程序博客网 时间:2024/05/01 11:12
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="angular-1.3.0.js"></script> <script> // 依赖注入:5个重要的组件factory、provider、service、value、constant var app = angular.module("myapp", []); //第一种factory// app.factory("calculator", function () {// return {// add: function (a, b) {// return a + b;// },//// subtract: function (a, b) {// return a - b;// },//// multiply: function (a, b) {// return a * b;// },//// divide: function (a, b) {// if (b != 0) {// return a / b;// }// return 0;// }// };// }); //第二种provider// app.provider("calculator",function(){// this.$get = function(){// return {// add: function (a, b) {// return a + b;// },//// subtract: function (a, b) {// return a - b;// },//// multiply: function (a, b) {// return a * b;// },//// divide: function (a, b) {// if (b != 0) {// return a / b;// }// return 0;// }// }// }// }); //第三种service 单例 app.service("calculator",function(){ this.add = function (a, b) { return a + b; }; this.subtract = function (a, b) { return a - b; }; this.multiply = function (a, b) { return a * b; }; this.divide = function (a, b) { if (b != 0) { return a / b; } return 0; } }); //value// app.value("a", "除数不能等于零!");// app.value("a", "除数不能等于零!!!!!");// app.controller("myCtrl", function ($scope, a) {// //输出的是 "除数不能等于零!!!!!" 下面覆盖了// console.log(a);// }); //constant app.constant("a", "除数不能等于零!"); app.constant("a", "除数不能等于零!!!!!"); app.controller("myCtrl", function ($scope, a) { //输出的是 "除数不能等于零!" 下面没有覆盖 console.log(a); }); app.controller("myCtrl", function ($scope, calculator) { //赋值 calculator是方法的第一个参数 $scope.result1 = calculator.add(8, 4); $scope.result2 = calculator.subtract(8, 4); $scope.result3 = calculator.multiply(8, 4); $scope.result4 = calculator.divide(8, 4); }); </script></head><body ng-app="myapp"><div ng-controller="myCtrl"> <div>8 + 4 = {{ result1 }}</div> <div>8 - 4 = {{ result2 }}</div> <div>8 * 4 = {{ result3 }}</div> <div>8 / 4 = {{ result4 }}</div></div></body></html>
阅读全文
0 0
- html5_依赖注入的5个重要的组件
- 理解ASP.NET MVC的DependencyResolver组件 (依赖注入)
- angular js 依赖注入的5大核心组件的理解和使用。
- spring 的依赖注入
- Spring的依赖注入
- Spring的依赖注入
- 常见的依赖注入
- spring的依赖注入
- 依赖注入的理解
- spring的依赖注入
- 依赖注入的好处
- 依赖注入的方式
- spring的依赖注入
- Spring的依赖注入
- Spring的依赖注入
- 依赖注入的方式
- Spring的依赖注入
- 依赖注入的方式
- Linux单元小结(8)
- go拾遗
- 周志华机器学习第一章习题
- 过敏预防
- atom DIY platformio-ide-terminal主题
- html5_依赖注入的5个重要的组件
- 初学opencv遇到的问题及解决办法
- ubuntu开启远程ssh登陆本机功能
- java中的垃圾回收机制
- Zookeeper简介
- 当面试官问你“业余爱好”时如何巧妙回答呢?
- JavaWeb第二章HTML与CSS网页03
- String prototype一个 小字符串方法,感觉他挺好的,原型链是个好东西
- 固定定位