角混入整合 [英] Angular Mixins integration

查看:73
本文介绍了角混入整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的所有模块之中一种功能,我想知道这个集成。角是否支持某种形式混入的?

I'm trying to offer a SORT functionality amongst all my modules and I'd like to know integrate this. Does Angular support some sort of mixin?

我想要混入注入新的特性(型号)和方法相关的模块控制器。这些属性和方法应该只使用其相关的控制器的范围。

I'd like the mixin to inject new properties (models) and methods to the controller associated to the module. These properties and methods should only use their associated controller's scope.

我知道我可以使用下划线_.extend或jQuery.extend(),但我想知道是否有一个真正的角精神要做到这一点更清洁的方式。

I know I could use underscore _.extend or jQuery.extend() , but I'd like to know if there's a cleaner way to do this in a true Angular spirit.

问候。

推荐答案

是的!它是非常简单的。

Yes! and it is very simple.

我可以给你一个例子如何实现的是:

I can give you an example how to achieve that:

(...)

.controller('ParentCTRL', ['$scope', function($scope) {

    $scope.base_func= function() {
        //Do something
    };
}]);

.controller('ChildrenCTRL', ['$controller', '$scope', function($controller, $scope) {

    $controller('ParentCTRL', {$scope: $scope});
    // Now you can access base_fun() from here

}]);

.controller('SecondChildrenCTRL', ['$controller', '$scope', function($controller, $scope) {

    $controller('ParentCTRL', {$scope: $scope});
    // Now you can access base_fun() from here

}]);

这篇关于角混入整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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