angularjs-controller

AngularJS: code not working when iterating through object [duplicate]

自作多情 提交于 2019-12-18 09:33:49
问题 This question already has answers here : 'this' vs $scope in AngularJS controllers (7 answers) Closed 3 years ago . I am trying to populate a list of employee objects from my controller empctrl in a template. Here's the controller: app.controller('employeeController', function ($scope, employeeService) { this.employees = {}; this.populateTable = function (data) { this.employees = data; }; var error = function (err) { console.log("Error: " + err); }; // Call Service to List all Employees

Initialize $scope variables for multiple controllers - AngularJS

99封情书 提交于 2019-12-18 05:15:13
问题 I have 3 controllers that do similar tasks: PastController queries an API for past system outages. CurrentController queries an API for current system outages FutureController queries an API for future system outages They are each unique (despite their similar functions). However, they all begin by defining the same $scope variables: app.controller("PastController", function ($scope) { $scope.Outages = ""; $scope.loading = 0; $scope.nothing = 0; $scope.error = 0; //--- code continues ---// })

How can we test non-scope angular controller methods?

若如初见. 提交于 2019-12-17 22:40:13
问题 We have few methods in Angular Controller, which are not on the scope variable. Does anyone know, how we can execute or call those methods inside Jasmine tests? Here is the main code. var testController = TestModule.controller('testController', function($scope, testService) { function handleSuccessOfAPI(data) { if (angular.isObject(data)) { $scope.testData = data; } } function handleFailureOfAPI(status) { console.log("handleFailureOfAPIexecuted :: status :: "+status); } // this is controller

Load controller dynamically based on route group

前提是你 提交于 2019-12-17 18:14:25
问题 Is it possible to load a controller, it's js file, and a template dynamically based on a route group? Psuedo code which doesn't work: $routeProvider.when('/:plugin', function(plugin) { templateUrl: 'plugins/' + plugin + '/index.html', controller: plugin + 'Ctrl', resolve: { /* Load the JS file, from 'plugins/' + plugin + '/controller.js' */ } }); I've seen a lot of questions like this one but none that loads the js file/controller based on a route group. 回答1: I managed to solve it inspired by

AngularJS : The correct way of binding to a service properties

孤街醉人 提交于 2019-12-17 05:17:31
问题 I’m looking for the best practice of how to bind to a service property in AngularJS. I have worked through multiple examples to understand how to bind to properties in a service that is created using AngularJS. Below I have two examples of how to bind to properties in a service; they both work. The first example uses basic bindings and the second example used $scope.$watch to bind to the service properties Are either of these example preferred when binding to properties in a service or is

How do I inject a controller into another controller in AngularJS

梦想的初衷 提交于 2019-12-16 22:35:37
问题 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

Angularjs Uncaught Error: [$injector:modulerr] when migrating to V1.3

泪湿孤枕 提交于 2019-12-16 19:55:58
问题 I am learning Angular.js and I am not able to figure out whats wrong with this simple code. It seems to look fine but giving me following error. **Error**: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=app&p1=Error%3A%20…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381) And before adding ng-app= "app" (I was just keeping it as ng-app ) it was giving me following errors. Why is that? Error: [ng:areq] http://errors

Referencing the element that is calling a controller function Angularjs ( ng-change / ng-blur / ng-* ? )

限于喜欢 提交于 2019-12-14 03:02:43
问题 The original question asked about how to determine which element called the controllers blurr function, but I didn't clarify that I was not specifically asking about ng-blur , but ng-* ( ng-change , ng-focus , ng-mouseover , ng-*) in general. So, with that in mind: How do I determine which element input is calling the blurr() and/or check() functions? html <body ng-app="test"> <div ng-controller="Cntrlr as cntrlr"> <form name="meta_test"> <input type="text" name='inpt' ng-model="cntrlr.inpt"

Controller doesn't work after URL change

旧城冷巷雨未停 提交于 2019-12-13 06:01:29
问题 In short: I have a controller that triggers some jQuery in my AngularJS web page to fade out a play button and a corresponding image. But, when the URL changes, the controller fails to work on subsequent pages. I'm using a dynamic URL, and I think that's why my controller is breaking. Detail I've organized my controllers by having one for each page of my website app. Here you can see how my routes are setup: angular.module('100_Ages', ['mydirectives', 'ngResponsiveImages']). config(['

AngularJS ng-bind-html 2way data binding

巧了我就是萌 提交于 2019-12-13 04:06:44
问题 I have an AngularJS app where I got some data from a webservice and parse some HTML to the template with ng-bind-html ... but when I try to bind data inside the ng-bind-html - nothing happens .. anyone? I have a little example here,.. not the right case. HTML <div ng-controller="MyCtrl"> <div ng-bind-html="post"></div> </div> Javascript angular.module('myApp',[]) .controller('MyCtrl', function($scope, $sce) { $scope.name = 'World'; $scope.post = $sce.trustAsHtml("<h1>hello {{name}}</h1>"); })