zoukankan      html  css  js  c++  java
  • angularJS1笔记-(16)-模块里的constant、value、run

    index.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
    <div ng-app="myApp">
        <div  ng-controller="firstController">
    
        </div>
    </div>
    
    <script type="text/javascript" src="../../vendor/angular/angularJs.js"></script>
    <script type="text/javascript" src="app/index.js"></script>
    
    <script>
    </script>
    
    </body>
    </html>
    

      index.js:

    var myApp = angular.module('myApp', [], ['$provide', function ($provide) {
    
    }])
    //把name注入config
        .config(function (name) {
            console.log("config中的值:" + name)
    
        })
        //run是在config之后 在controller之前执行
        .run(function () {
            console.log("run在config之后在controller之前:" + 'run');
        })
        //定义常量 可以注入任何方法
        .constant('name', 'zhangsan')
        //只能注入到controller/service/factory
        .value('version', 'v-1.0')
        .controller('firstController', ['name', function (name) {
            console.log("controller中的值:" + name);
        }])
    

      运行结果:

  • 相关阅读:
    C++异常:exception
    C++关键字:explicit
    C++关键字:重学记录
    Unity jointmoto
    hashtable和hashmap
    Spring MVC 笔记 概述
    SQL上门2
    面试:A
    Java 初学者
    SQL上门
  • 原文地址:https://www.cnblogs.com/yk123/p/6917088.html
Copyright © 2011-2022 走看看