在功能Angularjs控制器嵌入 [英] Angularjs controller embed in a function

查看:213
本文介绍了在功能Angularjs控制器嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么样在一个函数嵌入angularjs控制器。这样我们就可以开始,每当我们想要的。

How about embedding angularjs controller in a function. So that we can initiate whenever we want.

 fucntion execute() {

 angular.controller('ProductsPageController', ['$scope', '$http',   'InitService', function ($scope, $http, InitService) {
 })

  }

我认为这是一个小白angularjs问题。请让我知道启动控制器不一样ngrouter等其他模块的最佳方法。

I think this a noob angularjs question. Please let me know the best approach to initiate controller without other modules like ngrouter etc..

推荐答案

你不需要添加任何函数内部控制器。 onece初始化它,你可以使用它。
例如:

you dont need to add controller inside any function. you can use it onece you initialize it. eg.

angular.controller('ProductsPageController', function  () {
// here you can wright your business logic
});

然后在你的应用程序初始化等等
您可以直接调用你的控制器。

then initialize it in your app so you can call your controller directly.

这篇关于在功能Angularjs控制器嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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