Questions tagged [angularjs-controller]

The AngularJS controller exposes the data that is to be displayed into the HTML view. It plays the essential role of the ModelView in the MVVM design pattern. The view is a part of the HTML template.

AngularJS promotes the MVVM Design pattern.

The angularjs controller exposes the data that is to be displayed into the html view. It plays the essential role of the ModelView in the MVVM design pattern. The view is a part of the HTML template.

When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller's constructor function. A new child scope will be available as an injectable parameter to the Controller's constructor function as $scope.

ngController
The ngController directive attaches a controller class to the view. This is a key aspect of how angular supports the principles behind the Model-View-Controller design pattern.

Reference:
https://docs.angularjs.org/guide/controller
https://docs.angularjs.org/api/ng/directive/ngController

1243 questions
16
votes
1 answer

Using a child controller from another module

I've defined a module and made it the main module for my app using the ng-app directive. I added two controllers to the main app using angular.module('myApp').controller(). One of those controllers has page wide scope whereas the other controller is…
James
  • 3,051
  • 3
  • 29
  • 41
15
votes
5 answers

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

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]…
14
votes
4 answers

Getting AngularJS Error: "[$rootScope:inprog] $digest already in progress" without a manual $apply

Other posts on this error always include someone trying to $apply without using a safe apply, but that's not the case in my example. My function IS successfully returning the data I requested from the API, but I can't clean this bug and it's driving…
14
votes
6 answers

AngularJS: how to bind a constant object to a directive

I've created a directive with a binding using "scope". In some cases, I want to bind a constant object. For instance, with HTML:
and…
13
votes
2 answers

Assign multiple controller in $stateProvider.state

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'…
13
votes
3 answers

AngularJS : How to create a two-way data binding between two isolated controllers and a shared service?

I am trying to create a two-way data binding between two isolated controllers and a shared service (which provides another isolated scope): app.factory("sharedScope", function($rootScope) { var scope = $rootScope.$new(true); scope.data =…
akashivskyy
  • 44,342
  • 16
  • 106
  • 116
12
votes
5 answers

Angular ui-router resolve value as string

With ui-router, I add all resolve logic in state function like this; //my-ctrl.js var MyCtrl = function($scope, customers) { $scope.customers = customers; } //routing.js $stateProvider.state('customers.show', { url:…
12
votes
2 answers

AngularJS: $scope.array.push() does not update the view, even with $apply

I'm trying to learn AngularJS and there is this thing that I don't understand, which seems like all the internet solved by using $scope.$apply, but I already use it and it does nothing. Basically, I use Twitter API to retrieve a timeline, and when…
12
votes
2 answers

AngularJS - How do I avoid using $timeout to wait for an element to be created?

Here is the idea: So I am trying to use an external library function to create some manipulation in the DOM in one of my controllers that my ng-repeat is connected to. Newest jsFiddle working but ... http://jsfiddle.net/GeorgiAngelov/KRbdL/150/ So…
11
votes
1 answer

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:
user9445158
11
votes
2 answers

How to do autocomplete dropdown as a grid in angularJS?

Here I created sample for autocomplete, which is working fine and I need to do some modification on this.currently it works like this but what I exactly need is I need to show the dropdown as grid view. some like this can any one help on…
11
votes
1 answer

Angular ui.router, call parent controller function from child controller?

I'm using Angular with ui.router and have setup a nested view. The parent view has a div whose visibility I can toggle through a function on the parent controller. I'd like to call this function from the child controller of the nested view. How…
adam0101
  • 29,096
  • 21
  • 96
  • 174
10
votes
2 answers

Access AngularJs directive variable inside controller

I'm little bit new to Angularjs. What I want is access "$scope.myVar" variable inside 'myController' controller. It would be great help if you can provide a solution. angular.module('myDirective', []) .controller('myController',…
vimuth
  • 5,064
  • 33
  • 79
  • 116
10
votes
3 answers

Using controller inside another controller in AngularJS

Why I can't bind to controller's variable inside second controller?
Main:
{{state}}
10
votes
2 answers

AngularJS : passing params from controller to service

I'm having trouble on figuring out how to pass parameters from my angular controller to service #my controller 'use strict'; angular.module('recipeapp') .controller('recipeCtrl', ['$scope', 'recipeService', function($scope,…
sameera207
  • 16,547
  • 19
  • 87
  • 152
1 2
3
82 83