angularjs-controller

Call controller function from service in angularjs

谁都会走 提交于 2019-11-29 12:17:16
问题 I am using socket.io to enable chat in my app and i am using a service SocketService to perform all the socket stuff. When a message came then i want to trigger a function of a controller from the service SocketService to make some changes in the UI. So i want to know that how can i access the function of a controller from the service. Sample Code: .service('SocketService', function ($http,$rootScope,$q) { this.connect = function(){ var socket = io(); socket.on('connect',function(){ // Call a

What's the correct way to trigger jQuery DOM Manipulation from within a controller?

a 夏天 提交于 2019-11-29 09:33:20
问题 So I keep reading that jQuery manipulation from within a Controller is bad practice, but I'm not clear on why, or how to correct. Below is code from a Youtube tutorial which even the video creator comments is a bad idea, but doesn't explain why and continues to use the bad behavior anyway. From https://www.youtube.com/watch?v=ilCH2Euobz0#t=553s : $scope.delete = function() { var id = this.todo.Id; Todo.delete({id: id}, function() { $('todo_' + id).fadeOut(); }); }; SOLUTION : Based on Langdon

Initialize $scope variables for multiple controllers - AngularJS

╄→尐↘猪︶ㄣ 提交于 2019-11-29 08:27:22
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 ---// }); app.controller("CurrentController", function ($scope) { $scope.Outages = ""; $scope.loading = 0;

Simple Angular $routeProvider resolve test. What is wrong with this code?

╄→гoц情女王★ 提交于 2019-11-29 07:37:25
I have created a simple Angular JS $routeProvider resolve test application. It gives the following error: Error: Unknown provider: dataProvider <- data I would appreciate it if someone could identify where I have gone wrong. index.html <!DOCTYPE html> <html ng-app="ResolveTest"> <head> <title>Resolve Test</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js"> </script> <script src="ResolveTest.js"></script> </head> <body ng-controller="ResolveCtrl"> <div ng-view></div> </body> </html> ResolveTest.js var rt = angular.module("ResolveTest",[]); rt.config(["

Reinitialize an Angular.js controller

只谈情不闲聊 提交于 2019-11-29 03:07:05
if you have a controller to manipulate $scope variables in Angular.js, is there an idiomatic way to: reset the controller's $scope, and restart controller initialization? For complex controllers it would be very convenient not to have to reset every variable to it's initial value, especially if what you really want is a simple reinitialization of the controller and the scope. Navigating to the same URL again via $location.path() doesn't help, though. Edit: Suppose I can't use any $window.location hack because this would violate the CSP in Chrome Packaged Apps. Just after asking, I finally

How to access parent directive's controller by requiring it recursively?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 18:21:21
I'm trying to reach the controller of a parent "box" directive recursively: <body ng-app="main"> <!-- no nesting: parent is the just body --> <box></box> <script type="text/javascript"> angular.module('main', []) .directive('box', function() { return { restrict: 'E', controller: function() { }, require: '?^box', // find optional PARENT "box" directive link: function(scope, iElement, iAttrs, controller) { // controller should be undefined, as there is no parent box alert('Controller found: ' + (controller !== undefined)); } }; }); </script> </body> I'd expect controller variable to be undefined

AngularJS passing data to bootstrap modal

試著忘記壹切 提交于 2019-11-28 17:50:14
I think I'm missing something but cannot figure what. Basically I'm trying to pass an object to the modal like below, but instead of getting the passed object I gets null...so I think is a problem with the scope but I'm new in Angular and need some help. Controller app.controller("musicViewModel", function ($scope, $http, $location, $uibModal, $log) { $scope.selected = null; $scope.open = function (item) { $scope.selected = item; $log.info('Open' + $scope.selected); // get right passes object var modalInstance = $uibModal.open({ templateUrl: 'myModalContent.html', controller: 'musicViewModel',

Angular.js best practice - extending controllers, overriding controller defaults

瘦欲@ 提交于 2019-11-28 16:01:33
问题 Here is a real-life Angular problem I can't wrap my head around. I love Angular, but this issue is bugging me a lot right now. What is the best practice to extend an existing controllers's functions, and use the extended controller on an other page of my application? In other words: How to do controller inheritance in Angular? Edited out - 23/09/2014, dont think the description of my original usecase helps the visitors to understand it better what I'm after here. I think it disctracts people

AngularJS ng-controller not working

ぃ、小莉子 提交于 2019-11-28 09:01:50
I just now started learning on AngularJS from w3schools . I am trying to practice examples what ever they have mentioned in the tutorials. Every thing works fine but when i came to "AngularJS Controllers" it is not working properly as working well in w3schools Try it Yourself » . I ve forked my code into this fiddle example . My script looks like this: function personController($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; } Try to help me out and suggest me a good tutorial(or any free pdf file). This is your corrected fiddle . It is a good practice for angular that the

AngularJs - Error: 10 $digest() iterations reached. Aborting

∥☆過路亽.° 提交于 2019-11-28 07:45:01
I am trying to create a Metro Tile type grid with Angular, to achieve this i want each of the tiles to be a different colour. So my plan of action was to create a function that would randomly pick a colour inside a loop (using ng-repeat ). Here is what i have so far.... <div class={{RandomColourClass()}} ng-repeat="stockRecord in GridStockRecords | filter:searchText"> <div > <h6>{{stockRecord.ProductGroupName}}</h6> </div> </div> So as you can see i am setting the class name with a function called RandomColourClass, Here is the JS bits $scope.TileColours = [{colour:'thumbnail tile tile-blue'},