How to create separate AngularJS controller files?

I have all of my AngularJS controllers in one file, controllers.js. This file is structured as follows: angular.module('myApp.controllers', []) .controller('Ctrl1', ['$scope', '$http', function($scope, $http) { }]) .controller('Ctrl2', ['$scope', '$http', function($scope, $http) } }]) What I'd like to do is put Ctrl1 and Ctrl2 into separate files. I would then include both fil

如何创建单独的AngularJS控制器文件?

我将所有的AngularJS控制器放在一个文件中,controllers.js。 这个文件的结构如下: angular.module('myApp.controllers', []) .controller('Ctrl1', ['$scope', '$http', function($scope, $http) { }]) .controller('Ctrl2', ['$scope', '$http', function($scope, $http) } }]) 我想要做的是将Ctrl1和Ctrl2放入单独的文件中。 然后,我会将这两个文件都包含在我的index.html中,但应该如何构建? 我试图做这

AngularJS : Difference between the $observe and $watch methods

I know that both Watchers and Observers are computed as soon as something in $scope changes in AngularJS. But couldn't understand what exactly is the difference between the two. My initial understanding is that Observers are computed for angular expressions which are conditions on the HTML side where as Watchers executed when $scope.$watch() function is executed. Am I thinking properly?

AngularJS:$ observe和$ watch方法之间的区别

我知道,只要AngularJS中$scope某些内容发生变化, Watchers和Observers被计算出来。 但不明白这两者之间究竟有什么区别。 我最初的理解是Observers计算角度表达式,这是HTML端的条件,当$scope.$watch()函数执行时, Watchers执行这些条件。 我在想什么? $ observe()是Attributes对象上的一个方法,因此它只能用于观察/观察DOM属性的值更改。 它只用于/叫做内部指令。 当您需要观察/观看包含插值的DOM属性(即{{}})

AngularJS $http and $resource

I am newly exposed to AngularJS, so please forgive my ignorance. I have some web services that I want to call. $resource or $http , which one should I use? $resource : https://docs.angularjs.org/api/ngResource/service/$resource $http : https://docs.angularjs.org/api/ng/service/$http After I read the two above API pages I am lost. Could you please explain to me in plain English what is

AngularJS $ http和$资源

我刚接触AngularJS,所以请原谅我的无知。 我有一些我想要调用的Web服务。 $resource或$http ,我应该使用哪一个? $resource :https://docs.angularjs.org/api/ngResource/service/$resource $http :https://docs.angularjs.org/api/ng/service/$http 在阅读上述两个API页面之后,我迷失了方向。 你能用简单的英语向我解释什么是不同的,我应该在什么情况下使用它们? 我如何构造这些调用并将结果正确读入js对象

Inject a factory in a controller in angular

I´m trying to inject a factory in a controller in Angular, but I can not do. It is my code. app.controller('ManejadorEventosVista', ['AdministradorMarcador', ManejadorEventosVista]); 'app' is the variable that corresponds to the module with their respective dependencies. The controller is 'ManejadorEventosVista' and requires the services provided by the facto

以角度在控制器中注入工厂

我正尝试在Angular的控制器中注入一个工厂,但我做不到。 这是我的代码。 app.controller('ManejadorEventosVista',['AdministradorMarcador',ManejadorEventosVista]); 'app'是对应于具有各自相关性的模块的变量。 控制器是'ManejadorEventosVista',并且需要工厂'AdministradorMarcador'提供的服务。 函数ManejadorEventosVista(){} 但是当我想在这部分代码中使用工

Angularjs: Services and ui.router

I use an angular service for rendering a map and I injected it into my controller. By using ui.router, when I go to map page for first time, the map renders successfully, but when routing to other page and come back to map page again, the map does not renders, and I should refresh the page for it. I used both factory and service for it, but still there is a problem! Any idea? Here is my servi

Angularjs:服务和ui.router

我使用角度服务来渲染地图,并将其注入到我的控制器中。 通过使用ui.router,当我第一次转到地图页面时,地图呈现成功,但当路由到其他页面并再次返回到地图页面时,地图不会呈现,我应该刷新页面。 我使用了factory和service ,但仍然存在问题! 任何想法? 这是我的服务和控制器: angular.module('app') .service('mapService', function () { var _map = new ol.Map({ target: 'map-canva

router resolve factory undefined

I've followed the examples on the UI-Router wiki and the sample here: https://scotch.io/tutorials/angular-routing-using-ui-router but the resolved factory is undefined when it is injected into the controller. Any help would be greatly appreciated. app var app = angular.module('toa', ['ngResource', 'ui.bootstrap', 'ui.router']); app.config(function($statePro

路由器解析工厂未定义

我已经在UI-Router wiki和示例中遵循这些示例:https://scotch.io/tutorials/angular-routing-using-ui-router,但解析后的工厂在注入控制器时未定义。 任何帮助将不胜感激。 app var app = angular.module('toa',['ngResource','ui.bootstrap','ui.router']); app.config(function($stateProvider, $urlRouterProvider){ $urlRouterProvider.otherwise('/'); $stateProvider.s

Still confused about angularjs services and factories

I've read several threads about angularjs services and factories. I understand that services are singletons and factories return instances of objects. But I still don't really understand how to use them. My app is a simple social network. The person using the app needs to log in, then they can view other members and send them messages. My ideal design would be: Create a Member obj

仍然对angularjs服务和工厂感到困惑

我已经阅读了几个关于angularjs服务和工厂的主题。 我明白,服务是单身人士,工厂返回对象的实例。 但我仍然不太明白如何使用它们。 我的应用是一个简单的社交网络。 使用该应用程序的人需要登录,然后他们才能查看其他成员并向他们发送消息。 我的理想设计是: 创建一个成员对象来表示我的服务的任意成员。 每当'list'或'get'操作返回数据时,它都会被封装在这个成员中,所以我可以调用它的实用方法。

Some problems about DI in angular.js

I am practicing DI and tried to be modular in angular.js.I had searched some tutorial and try to recode it. What I plan at first is as following(I might have the wrong concepts,please help to point out): An ng-app:myapp; An module "finance2" with an factory service:"currencyConverter"; angular.module('finance2', []).factory('currencyConverter', function() { An module &q

有关angular.js中DI的一些问题

我正在练习DI,并尝试在angular.js.中进行模块化。我已经搜索了一些教程并尝试对其进行重新编码。 我最初的计划如下(我可能有错误的概念,请帮忙指出): 一个ng-app:myapp; 带有工厂服务的模块“finance2”:“currencyConverter”; angular.module('finance2', []).factory('currencyConverter', function() { 带控制器的模块“ctrl1”:InvoiceController。 然后我将服务模块注入它 angular.module('ctrl1',['finance2'])

AngularJS : What is a factory?

I've been doing a lot of work on Angular.js and overall I find it to be an interesting and powerful framework. I know there have been a lot of discussions on Services vs. Factories vs. Providers vs. Values, but I am still pretty confused about what a Factory is. Factory has been defined in other StackOverflow discussions as the following: Factories Syntax: module.factory( 'factory

AngularJS:什么是工厂?

我在Angular.js上做了很多工作,总的来说我觉得它是一个有趣而强大的框架。 我知道有很多关于服务与工厂vs.提供商与价值的讨论,但我仍然对Factory是什么感到困惑。 工厂已在其他StackOverflow讨论中定义如下: 工厂 语法: module.factory( 'factoryName', function ); 结果:将factoryName声明为注入参数时,将提供通过调用传递给module.factory的函数引用返回的值。 我觉得这个解释很难理解,并且不会增加

Working with $scope.$emit and $scope.$on

How can I send my $scope object from one controller to another using .$emit and .$on methods? function firstCtrl($scope) { $scope.$emit('someEvent', [1,2,3]); } function secondCtrl($scope) { $scope.$on('someEvent', function(mass) { console.log(mass); }); } It doesn't work the way I think it should. How do $emit and $on work? First of all, parent-child scope relation does matter.

使用$ scope。$ emit和$ scope。$ on

如何使用.$emit和.$on方法将$scope对象从一个控制器发送到另一个控制器? function firstCtrl($scope) { $scope.$emit('someEvent', [1,2,3]); } function secondCtrl($scope) { $scope.$on('someEvent', function(mass) { console.log(mass); }); } 它不以我认为应该的方式工作。 $emit如何$emit和$on工作? 首先,亲子范围关系很重要。 你有两种可能性来发出一些事件: $broadcast - 向下调度事件给所有子范