javascript - Angular 模块私有(private)成员

标签 javascript angularjs angularjs-module

在 AngularJS 中,是否可以创建私有(private) Controller 或服务,这些 Controller 或服务可以在定义它们的模块中使用,但不能由它们注入(inject)的另一个模块使用。

比如PrivateController是否可以设为子模块私有(private):

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>

最佳答案

,在当前版本的 AngularJS 中无法创建“私有(private)”服务。有一些关于支持私有(private)(模块范围)服务的讨论,但没有实现。

截至今天,在给定模块上公开的所有服务对所有其他模块都是可见的。

关于javascript - Angular 模块私有(private)成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16950246/

相关文章:

javascript - jquery 复选框 - 检查数组中的值并检查这些值

javascript - 将多个图像下载到 1 个 zip 文件中

javascript - Parse.com 创建具有关系的对象

javascript - 如何删除无法创建图表: can't acquire context from the given item error while using it with Ruby on Rails?

css - 如何使用 ionic 滚动并在上方固定内容

AngularJS:使用多模块并在模块之间进行通信?

javascript - AngularJs 中的函数问题

javascript - 交换 AngularJS 语法导致错误

javascript - 具有多个 Mongo DB 的 Meteor

javascript - angularjs 和 mocha 测试 Uncaught TypeError : (window. beforeEach || window.setup) 不是函数