AngularJS模块依赖 - 澄清? [英] AngularJS module dependencies - clarification?

查看:106
本文介绍了AngularJS模块依赖 - 澄清?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经调查从AngularJs的网站教程示例( 这个

I've been investigating the tutorial example from AngularJs's site ( this one)

(href=\"http://angular.github.io/angular-phonecat/step-11/app/#/phones\" rel=\"nofollow\">主HTML中的(除 NG-视图 NG-应用= phonecatApp ))

(The main html is pretty empty (except for ng-view and ng-app=phonecatApp))

app.js 文件中包含的:

var phonecatApp = angular.module('phonecatApp', [
  'ngRoute',
  'phonecatControllers',
  'phonecatFilters',
  'phonecatServices'
]);

phonecatApp.config(['$routeProvider',...

好了,所以我们有 phonecatApp 模块,许多依赖。

但后来我看到了 controller.js 文件(他们打开控制器一个新的模块)

But then I saw the controller.js file ( they opened a new module for the controllers)

/*1*/   var phonecatControllers = angular.module('phonecatControllers', []);
/*2*/   
/*3*/   phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'Phone',
/*4*/     function($scope, $routeParams, Phone) {
/*5*/       ...
/*6*/       });
/*7*/   
/*8*/     }]);

电话是一种服务。 (这是对的其他的模块,不同的js文件)

Phone is a service. ( which is on another module , different js file)

在线路#3,它是如何知道什么是电话参数?他们没有加入行#1的dependecy模块!结果
同为 $ routeParams 如何它知道吗?他们的没有加入行#1任何依赖于 ngRoute

In line #3 , how does it know what is the Phone parameter ? they didnt add any dependecy module in line #1 !
Same for the $routeParams , how does it know it ? they didn't add any dependency in line #1 to the ngRoute !

我失去了一些东西在这里?

Am I missing something here ?

推荐答案

依赖注入的工作原理是默认的角度每一个组件。

The dependency injection works by default for every component of Angular.

这是因为每一个组件是对象中定义的,所以它可以跟踪这一切。

This is because every component is defined inside the angular object, so it can track it all.

您可以检查此 http://docs.angularjs.org/guide/di 出要了解它是如何工作的。

You can check this http://docs.angularjs.org/guide/di out to understand how it works.

这篇关于AngularJS模块依赖 - 澄清?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆