角模块专用成员 [英] Angular Module Private Members
问题描述
在AngularJS,是有可能创造可以定义它们在模块内使用私有控制器或服务,但不被它们被注入到另一模块。
例如,可以PrivateController进行专用于儿童的模块:
angular.module('孩子',[]) .controller('PublicController',函数($范围){
$ scope.children = ['鲍勃','苏']; }) .controller('PrivateController',函数($范围){
$ scope.redHeadedStepChildren = ['比利','米尔德里德']; })angular.module('父',['孩子'])
< DIV NG-应用=父>
< DIV NG控制器='PublicController'>
< DIV NG重复='孩子在儿童>
{{儿童}}
< / DIV>
< / DIV> < DIV NG控制器='PrivateController'>
< DIV NG重复='孩子redHeadedStepChildren'>
{{儿童}}
< / DIV>
< / DIV>
< / DIV>
否,它是不可能在AngularJS的当前版本创建的私人的服务。大约有私人(模块范围的)服务的支持一些讨论,但没有实现。
从今天起所有暴露给定模块的服务对所有其他模块可见。
In AngularJS, is it possible to create private controllers or services which can be used within the module they are defined in, but not by another module they are injected into.
For example, can PrivateController be made private to the Child module:
angular.module('Child', [])
.controller('PublicController', function ($scope){
$scope.children = ['Bob', 'Sue'];
})
.controller('PrivateController',function ($scope){
$scope.redHeadedStepChildren = ['Billy', 'Mildred'];
})
angular.module('Parent', ['Child'])
<div ng-app="Parent">
<div ng-controller='PublicController'>
<div ng-repeat='child in children'>
{{child}}
</div>
</div>
<div ng-controller='PrivateController'>
<div ng-repeat='child in redHeadedStepChildren'>
{{child}}
</div>
</div>
</div>
No, it is not possible to create "private" services in the current version of AngularJS. There were some discussions about support for private (module-scoped) services but it is not implemented.
As of today all the services exposed on a given module are visible to all other modules.
这篇关于角模块专用成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!