简体   繁体   English

如何在Angular.js中实例化控制器?

[英]How to instantiate controller in Angular.js?

I would like to use Angular with non-DOM view (using Pixi.js), so I need to instantiate controller manually (analogical to ng-controller attribute), I found something like: 我想将Angular与非DOM视图一起使用(使用Pixi.js),所以我需要手动实例化控制器(与ng-controller属性类似),我发现类似以下内容:

$controller('MyController', {$scope: $scope}));

but it suppose I have already $scope created. 但它假设我已经创建了$ scope。

Note: I know Angular is mainly aimed to use DOM element, but for Pixi, it could be a little bit similar, I would use $watch and $apply for attributes like x, y, alpha etc. Thanks. 注意:我知道Angular主要针对使用DOM元素,但是对于Pixi来说,可能有点相似,我将对$ x,y,alpha等属性使用$ watch和$ apply。谢谢。

The most straightforward way to do this is like this: 最简单的方法是这样的:

angular.module('<module-name>', [])
    .controller('MyController', function ($scope) {
        ...
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM