Search Posts

Category: angularjs-controller

Returning data from service to controller return undefined in angularjs

I am implementing a basic websocket and angularjs applcation. I have a service which consoles a message on onmessage event. I want to return that message back to controller. But I am getting undefined in controller. Can someone help me out? Here’s my code of controller and service. Controller var app = angular.module(“test”); app.controller(‘LoginCtrl’,[“$scope”,”$window”,”Socket”,”$rootScope”, function ($scope, $window, socket, $rootScope) { $scope.connect = function () { socket.createConnection(); } $scope.disconnect = function () { socket.closeConnection(); } $scope.sendMessage […]

Visual Studio’s AngularJS Template Explained

When I create a new controller using VS2015 templates I get this code: (function () { ‘use strict’; angular .module(‘app’) .controller(‘controller’, controller); controller.$inject = [‘$scope’]; function controller($scope) { $scope.title = ‘controller’; activate(); function activate() { } } })(); Questions: Why does VS template wraps the code in a self invocing function? What’s the thing with the activate() function? What code do I suppose to write inside and why do I need a seperate function instead […]

Passing service as a parameter of controller function in Angularjs

I have controller, view and services in separate files of an Angular application. These files are: home.controller.js angular .module(‘loc8rApp’) .controller(‘homeCtrl’, homeCtrl); function homeCtrl () { var vm = this; vm.pageHeader = { title: ‘Loc8r’, strapline: ‘Find places to work with wifi near you’ }; } home.view.html <div id=”banner” class=”page-header”> <div class=”row”> <div class=”col-lg-6″></div> <h1> {{ vm.pageHeader.title }} <small>{{ vm.pageHeader.strapline }}</small> </h1> </div> </div> loc8rData.service.js angular .module(‘loc8rApp’) .service(‘loc8rData’, loc8rData); var loc8rData = function ($http) { var […]

angular watch not fired

There is 1 angular app, with 1 parent controller, and a child controller. In the child, there is 1 $watch WATCH-CHILD for OBJ-CHILD, which triggers an $emit. In the parent, there is a listener for the $emit, we’ll call it ON-LISTENER, and a $watch WATCH-PARENT for OBJ-PARENT (which uses true as the 3rd argument). When the child’s OBJ-CHILD is changed, it triggers WATCH-CHILD, which triggers the $emit. The parent listener ON-LISTENER is fired, and changes […]

Using angularjs 1.5.8 and ui router and got controller not defined error

I am building spring boot website using freemarker and angularjs as front end, using the example from and I have three controllers, BookController, WarehouseController and StocklistController, Here my add.js code: var app = angular.module(‘BookInventoryApp’,[‘ui.router’,’ngStorage’]); app.constant(‘urls’, { BASE: ‘http://localhost:8080/SpringBootApp’, INVENTORY_SERVICE_API : ‘http://localhost:8080/SpringBootApp/api/book/’, WAREHOUSE_SERVICE_API : ‘http://localhost:8080/SpringBootApp/api/warehouse/’, STOCKLIST_SERVICE_API : ‘http://localhost:8080/SpringBootApp/api/stock/’ }); app.config([‘$stateProvider’, ‘$urlRouterProvider’, function($stateProvider, $urlRouterProvider) { $stateProvider .state(‘home’,{ url: ‘/’, templateUrl: ‘home’ }) .state(‘home.Warehouse’, { url: ‘/warehouse’, templateUrl: ‘partials/warehouselist’, controller:’WarehouseController’, controllerAs:’ctrl’, resolve: { warehouses: function ($q, WarehouseService) […]

Dealing with AngularJS services, $http and controllers [duplicate]

This question already has an answer here: Return http data from Angular service 2 answers I have a big problem in probably understanding how services work. Pratically, i wanted to develop a simple ToDo application with Bootstrap and AngularJS, but today, better understanding what services are, i have passed my “printToDo” function from the controller to the service; but something went wrong and after a whole day spent i cannot understand anyway what it’s broken, […]

HTTP GET Calling Multiple times in AngularJS Factory

I have created the angular Factory to get the results from the PHP and calling only one time but when I see in the Network its calling multiple times as shown below and its taking lot of time to get the response from PHP I have attached the screenshot of the Network Tab where I am seeing multicurl.php is called 3 times, Since it is very data I have to make sure its called only […]

Issue while creating a controller in AngularJS

I am new to AngularJS. I am working on login functionality using forms in html and angularjs. There are three files 1. index.html 2. app.js 3. LoginCntrl.js I have included both the js files in .html file but the ng-controller is not working. It isn’t taking values from controller and not even calling functions in the controller. The js files are being executed but I think there is something wrong in my html file. Here […]