zoukankan      html  css  js  c++  java
  • Angular 学习笔记——service &constant

    <!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>
  • 相关阅读:
    BZOJ 4260: Codechef REBXOR (trie树维护异或最大值)
    BZOJ 3744 Gty的妹子序列 做法集结
    BZOJ 3289: Mato的文件管理 (区间查询逆序对)
    [JSOI2007]文本生成器
    [TJOI2013]单词
    模板 AC自动机
    POJ 3710 Christmas Game
    HDU 3094 A tree game
    BZOJ 3817 Sum
    BZOJ 4589 Hard Nim
  • 原文地址:https://www.cnblogs.com/mayufo/p/5031602.html
Copyright © 2011-2022 走看看