angularjs-controller

Assign multiple controller in $stateProvider.state

不想你离开。 提交于 2020-01-12 04:33:27
问题 Probably this is an easy question for advanced angular users, but I did not find this issue somewhere well explained. So I was restructuring my code, when I realized, I have two controllers in a view, which is not a problem, when controller 'ACtrl' is binded by the $stateProvider and controller 'BCtrl' is binded in the view by ng-controller. But when I try to assign both of them in the $stateProvider like this: $stateProvider.state('a.view', { url: "/anurl", views: { 'menuContent': {

Assign multiple controller in $stateProvider.state

会有一股神秘感。 提交于 2020-01-12 04:33:05
问题 Probably this is an easy question for advanced angular users, but I did not find this issue somewhere well explained. So I was restructuring my code, when I realized, I have two controllers in a view, which is not a problem, when controller 'ACtrl' is binded by the $stateProvider and controller 'BCtrl' is binded in the view by ng-controller. But when I try to assign both of them in the $stateProvider like this: $stateProvider.state('a.view', { url: "/anurl", views: { 'menuContent': {

Communication between controllers in Angular

只愿长相守 提交于 2020-01-11 19:00:14
问题 I'm familiar with the following methods to implement communication between controllers. Are there others? Are there better approaches / best practices? $broadcast / $emit .controller("Parent", function($scope){ $scope.$broadcast("SomethingHappened", {..}); $scope.$on("SomethingElseHappened", function(e, d){..}); }) .controller("Child", functions($scope){ $scope.$broadcast("SomethingElseHappened", {..}); $scope.$on("SomethingHappened", function(e, d){..}); }) .controller("AnotherChild",

How to make so a controller block is executed everytime a state is accessed?

别说谁变了你拦得住时间么 提交于 2020-01-11 06:42:11
问题 I have a controller attached to a state, and everytime said state is accessed, I need my controller to run a block where I do a verification. How can I do this? 回答1: For reloading controller every time you should mention reload: true option on you .state declaration of ui-router Sample Code $stateProvider .state('state1', { templateUrl: 'state1.html', controller: `state1Ctrl`, reload: true //forcefully reload route and load controller again }) Also you could refer this SO Question 回答2: In

Cannot write a basic controller AngularJS

青春壹個敷衍的年華 提交于 2020-01-07 02:56:26
问题 Forgive me if my question is too basic. I am learning AngularJS's controllers. This is the project structure. This is my html: <!doctype html> <html ng-app> <head> <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script> <script src="js/controllers.js" /> </head> <body> <div ng-controller="numberController"> <input type = "text" ng-model = "number.number1" placeholder = "Enter a number here"> <input type = "text" ng-model = "number.number2" placeholder =

Value of variable becomes undefined after calling data service

强颜欢笑 提交于 2020-01-06 13:12:42
问题 I have a angular js controller 'TakeSurveyController' which calls a data service 'takeSurveyDataService'. The controller has a variable empId which I am accessing successfully using the 'this' keyword. However, the value of this variable becomes undefined soon after I make a call to the data service. (function(){ dataUrls = { employeeUrl : '/SurveyPortal/Company/Employees/' } angular.module('takeSurvey',[]) .service('takeSurveyDataService',function($http,$log){ this.checkEmployee = function

Value of variable becomes undefined after calling data service

痴心易碎 提交于 2020-01-06 13:11:03
问题 I have a angular js controller 'TakeSurveyController' which calls a data service 'takeSurveyDataService'. The controller has a variable empId which I am accessing successfully using the 'this' keyword. However, the value of this variable becomes undefined soon after I make a call to the data service. (function(){ dataUrls = { employeeUrl : '/SurveyPortal/Company/Employees/' } angular.module('takeSurvey',[]) .service('takeSurveyDataService',function($http,$log){ this.checkEmployee = function

angularjs controller in PartialView not working

浪子不回头ぞ 提交于 2020-01-05 10:38:37
问题 I have a View which contains a link to call a PartialView. <div data-ng-controller="MainController"> <a href="#" data-ng-click=callPartialView()"> Click here to see the details. </a> </div> <script> app.controller('MainController', ['$scope', 'HttpService', function($scope, HttpService) { $scope.callPartialView = function() { HttpService.getModal('/Controller/ShowModalMethod', {}); }; }]); </script> My HttpService service has a function that calls an action from the controller and returns a

Why does this AngularJs Service with variable object name return an undefined object?

人盡茶涼 提交于 2020-01-04 02:35:19
问题 Scenario : I'd like to use this service to share some properties inside my webApp. This service should have some object inside and the controllers should be able to get and set those objects. JS : var oneApp = angular.module('myApp', ['ui.bootstrap', 'ngTouch', 'ngAnimate']) .service('sharedProps', function() { var anObjNameDest = ''; var anObjPropName = ''; this.progressBarDynTyped00 = { dynamic: 0, dynMultiplier: 10, max: 100 }; var progressBarDynTyped00 = { dynamic: 1000, dynMultiplier:

Jasmine Test in Angular for controller

梦想的初衷 提交于 2020-01-04 02:03:08
问题 I get the following error: TypeError: undefined is not a function The problem is that the common is module and a factory and the problem is on my line var ctrl = $controllerConstructor("resetPasswordSentScreen", { $scope: scope, common: common}); Here is the full test: describe('resetPasswordSentScreen', function () { var scope, $controllerConstructor; beforeEach(module('common', 'app')); beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); $controllerConstructor =