zoukankan      html  css  js  c++  java
  • angular js的Inline Array Annotation的理解

    inline Array annotation的形式是:

    someModule.controller('MyController', ['$scope', 'greeter', function($scope, greeter) {
      // ...
    }]);
    其中function($scope,greeter){}分别代表$scope对象,greeter对象。

    现在我把上面的代码改动一点:
    someModule.controller('MyController', ['$scope', 'greeter', function(a,b) {
      // ...
    }]);
    其中参数a代表的是$scope对象,参数b代表的是greeter对象,至于我们在开发时把参数和和参数所代表的对象取相同的名字是为了见名知义。
    下面的代码是参数的名字和对象名字不一致的情况:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <script src="../materialDesignfile/angular.js"></script>
        <script>
           angular.module('myApp',[])
               .factory('myService',function () {
                   var factory={};
                   factory.name="ouyangfeng";
                   factory.sayHello=function () {
                       debugger
                       console.log("say hello");
                   }
                   return factory;
               })
    //sixi代表的对象是$scope,ouyangfeng代表的对象是:myService. .controller(
    'myCtrl',['$scope','myService',function (sixi,ouyangfeng) { sixi.sixi="泗溪"; debugger sixi.hello=ouyangfeng.sayHello; sixi.name=ouyangfeng.name; }]); </script> <div ng-app="myApp" ng-controller="myCtrl"> <h1>{{sixi}}</h1> <button ng-click="hello()">hello</button> <h1>{{name}}</h1> </div> </body> </html>
     
     
  • 相关阅读:
    Spring事务
    org.apache.catalina.webresources.Cache.getResource Unable to add the resource
    CentOS7下zip解压和unzip压缩文件
    通过Maven插件发布JaveEE项目到tomcat下
    MYSQL5.7版本sql_mode=only_full_group_by问题
    CentOS下安装Tomcat
    MYSQL57密码策略修改
    CentOS下安装mysql5.7和mysql8.x
    Linux下使用systemctl命令
    076-PHP数组修改元素值
  • 原文地址:https://www.cnblogs.com/1540340840qls/p/7821079.html
Copyright © 2011-2022 走看看