angularjs-controller

Error: [ng:areq] from angular controller

ⅰ亾dé卋堺 提交于 2019-11-26 07:36:07
问题 This is a long shot, but has anyone seen this error before? I am trying to add \'Transporters\' using express, angular and mongoDB. I get this error whenever I access a page ruled by the transporters controller: Error: [ng:areq] http://errors.angularjs.org/1.2.12/ng/areq?p0=TransportersController&p1=not%20aNaNunction%2C%20got%20undefined at Error (native) at http://localhost:3000/lib/angular/angular.min.js:6:450 at tb (http://localhost:3000/lib/angular/angular.min.js:18:360) at Pa (http:/

Can an AngularJS controller inherit from another controller in the same module?

烈酒焚心 提交于 2019-11-26 02:04:29
问题 Within a module, a controller can inherit properties from an outside controller: var app = angular.module(\'angularjs-starter\', []); var ParentCtrl = function ($scope, $location) { }; app.controller(\'ChildCtrl\', function($scope, $injector) { $injector.invoke(ParentCtrl, this, {$scope: $scope}); }); Example via: Dead link : http://blog.omkarpatil.com/2013/02/controller-inheritance-in-angularjs.html Can also a controller inside a module inherit from a sibling? var app = angular.module(\

How do I use $rootScope in Angular to store variables?

蹲街弑〆低调 提交于 2019-11-26 00:35:49
问题 How do I use $rootScope to store variables in a controller I want to later access in another controller? For example: angular.module(\'myApp\').controller(\'myCtrl\', function($scope) { var a = //something in the scope //put it in the root scope }); angular.module(\'myApp\').controller(\'myCtrl2\', function($scope) { var b = //get var a from root scope somehow //use var b }); How would I do this? 回答1: Variables set at the root-scope are available to the controller scope via prototypical

How do I inject a controller into another controller in AngularJS

倾然丶 夕夏残阳落幕 提交于 2019-11-26 00:26:44
I'm new to Angular and trying to figure out how to do things... Using AngularJS, how can I inject a controller to be used within another controller? I have the following snippet: var app = angular.module("testApp", ['']); app.controller('TestCtrl1', ['$scope', function ($scope) { $scope.myMethod = function () { console.log("TestCtrl1 - myMethod"); } }]); app.controller('TestCtrl2', ['$scope', 'TestCtrl1', function ($scope, TestCtrl1) { TestCtrl1.myMethod(); }]); When I execute this, I get the error: Error: [$injector:unpr] Unknown provider: TestCtrl1Provider <- TestCtrl1 http://errors

AngularJS: How can I pass variables between controllers?

北战南征 提交于 2019-11-25 22:24:59
问题 I have two Angular controllers: function Ctrl1($scope) { $scope.prop1 = \"First\"; } function Ctrl2($scope) { $scope.prop2 = \"Second\"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } I can\'t use Ctrl1 inside Ctrl2 because it is undefined. However if I try to pass it in like so… function Ctrl2($scope, Ctrl1) { $scope.prop2 = \"Second\"; $scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally } I get an error. Does anyone know