angularjs笔记-angular.module模块理解

html代码

<body ng-app="xmpl">	
<div ng-controller="XmplController">
  {{ greeting }}
</div>
</body>

js代码 

angular.module('xmpl.service', [])        //1.创建xmpl.service模块
 
  .value('greeter', {
    salutation: 'Hello',
    localize: function(localization) {
      this.salutation = localization.salutation;
    },
    greet: function(name) {
      return this.salutation + ' ' + name + '!';
    }
  })
 
  .value('user', {
    load: function(name) {
      this.name = name;
    }
  });
 
angular.module('xmpl.directive', []);    //2.创建xmpl.directive模块
 
angular.module('xmpl.filter', []);         //3.创建xmpl.filter模块
 
//4.创建xmpl, 并且引用其他模块代码
angular.module('xmpl', ['xmpl.service', 'xmpl.directive', 'xmpl.filter'])    
 
  .run(function(greeter, user) {
    // This is effectively part of the main method initialization code
    greeter.localize({
      salutation: 'Bonjour'
    });
    user.load('World');
  })
 
  .controller('XmplController', function($scope, greeter, user) {
    $scope.greeting = greeter.greet(user.name);
  });

1.ng-app的作用

<html ng-app="invoice1">将html定义为一个angular容器。

2.angular.module("invoice1", [])模块的作用

angular.module以ng-app同名invoice1容器创建一个代码模块。将容器与模块对应。

目前的理解模块就是代码的封装吧。单一职责原则,一个模块专心负责一个业务类型。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值