Search Posts

Category: angularjs-controller

AngularJS Directive with Controller Constructor Never Fires

Hi I am trying to write a angularJS directive with a controller in typescript but I can’t seem to get my constructor to fire inside the controller. I have searched the internet extensively but have not been able to find much information as most people are not using typescript with angularJS. The version of angularJS I am using is 1.5.10. Any insight into this issue would be greatly appreciated. class AdvancedFindDirective implements ng.IDirective { public […]

console.log() not working inside Angularjs controller

There have been several posts related to this issue, but so far I have not found a resolution. Following is a slight modification of the example on pages 408-409 of Brad Dayley’s “Node.js. MongoDB and Angular Web Development” (the original edition, not the Second). The set up is as follows. Create a directory called “test” (or whatever you want) and in this directory (1) place the following file node_server.js, and (2) create a subdirectory called […]

AngularJS – Factory from Controller – not getting value from $http.get

I have a newbie question here. I am coding a factory in angularJS. With it I want to have a list of users, and also a method to fill it. So this is my code … The factory app.factory(“usuariosFactory”, function ($http) { var f = {}; f.users = []; f.getUsers = function (callback) { var token = window.localStorage.getItem(“_token”); $http.get(“http://localhost:8000/api/user/list?token=” + token).then(function (response) { f.users =; /* the console.log outputs OK with the users from […]

how to store same data in multiple $scope variables in same controller using angularjs

I have to store same data in two different scope variables. I have saved as per below code. app.controller(‘ClientsCtrl’, function ($scope, $http) { $scope.model = {}; $http.get(“client/getdata”, {}) .then(function (result) { //For e.g, I have received = ‘Weekly’ $scope.model = { edit:, show: }; }, function (error) { }); }); Used these scope variables to show and edit like <div> <div> Show Model Frequency: {{}}<br /><br /> Edit Model Frequency: {{model.edit.Frequency}} </div> […]

How can I pull a specific title from an array using Angular?

I am trying to pull a specific title from an array using Angular. Whilst I can use ng-repeat to loop through all titles and print these to my news listing webpage, I only wish to pull the first heading in my array for the news details page. Do I need to use the ng-repeat or can I use something different? I have tried using number:0 as well as json:0. $scope.newsListings = [ { title: “Why […]

Getting Function.prototype.bind.apply(…) is not a constructor error

I am trying to simulate Controller Inheritance in AngularJS (1.6.9), but I am getting an error on console as : Function.prototype.bind.apply(…) is not a constructor Here is the HTML file: <!– Controller Inheritance –> <!DOCTYPE html> <html lang=”en” ng-app=”app7″> <head> <meta charset=”UTF-8″> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <meta http-equiv=”X-UA-Compatible” content=”ie=edge”> <title>Tutorial 7</title> <script src=””></script> </head> <body> <div ng-controller=”mainCtrl as parent”> <p>Name: {{}}</p> <p>Sound: {{parent.sound}}</p> <button ng-click=”parent.animalClick()”>Animal Data</button> </div> <br><br> <div ng-controller=”dogCtrl as dog”> <p>Name: {{}}</p> <p>Sound: […]

AngularJS: Controller inside ng-view

how to AngularJS: Controller inside ng-view I have problem with controller load when I triggered ng-route. This is my main page: <!DOCTYPE html> <html> <head ng-app=”testapp”> <script type=”text/javascript” src=”angular.js”></script> <script type=”text/javascript” src=”angular-route.js”></script> <script type=”text/javascript” src=”app.js”></script> <title>XX</title> </head> <body> <nav ng-controller=”defaultnav”></nav> <div ng-view></div> </body> </html> and this is my app.js file: var app = angular.module(‘testapp’, [‘ngRoute’]); app.config(function ($routeProvider) { $routeProvider. when(“/”, { templateUrl: “index.html” }) .when(“/page1”, { templateUrl: “page1.html” }) }) inside the page1.html I inisiate […]

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 […]

Next Page »