Questions tagged [angularjs-controlleras]

The Controller As syntax provides a way to access properties and methods of a controller declared on the controller via this. The controller instance is being published as the specified property on the scope.

"Controller As" syntax was introduced in AngularJS 1.2. Per AngularJS doc:

Using controller as makes it obvious which controller you are accessing in the template when multiple controllers apply to an element.

This does not replace $scope. If some specific bindings/watchers/broadcasts/etc are needed, the $scope could be injected into the controller and used as usual.

Some helpful readings:

112 questions
1
vote
2 answers

Can you use ControllerAs syntax within separate Controllers that share the same view?

QUESTION: Can you use ControllerAs syntax within separate Controllers that share the same view? ie: (var vm = this)? DILEMMA I'm trying to get rid of the linter error in my console generated by EsLinter: "Designated alias 'vm' is not assigned to…
Crystal
  • 1,425
  • 1
  • 22
  • 34
1
vote
1 answer

Refactor AngularJS to use controllerAs, apply CSS for a required input once it is not empty

What would be the most efficient way of conditionally changing the background color for a required input once it is valid using AngularJS 1.5.6? Per my understanding and what I have read online, I should avoid using $scope and instead use…
1
vote
1 answer

AngularJS Material mdDialog and display locals in a template

Part of the controller which spawn mdDialog looks like $scope.removeAttendee = function(item) { console.log(item); $mdDialog.show({ controller: DialogController, templateUrl: 'views/removeMsg.tmpl.html', parent:…
1
vote
0 answers

Using ng-include with controller as syntax

I need to change the "controller as" name to ctrl in "_restaurantdiv.html" since I am using this partial file in different places under different controllers. Currently I am doing so by writing ng-controller along with ng-include. But the problem…
1
vote
1 answer

angular directive with controllerAs dosn't work

I'm struggling with making angular directive work with controllerAs. When using $scope everything work as expected but when get rid of $scope directive controller doesn't work. Please see the code below and plunker:…
1
vote
1 answer

How do I test controller as syntax with protractor?

I'm currently writing some Protractor tests for an app. But in the app i'm using controller as syntax as the pieces I want to work on are components. The problem is that when i use the selector of "" $ctrl.functionName"" it's giving me an illegal…
1
vote
2 answers

controllerAs, bindToController and watches

I had this directive which has a controller. It looked like this: .directive('pkSlider', ['$timeout', function ($timeout) { return { restrict: 'A', scope: { question: '=pkSlider', options: '=', …
r3plica
  • 13,017
  • 23
  • 128
  • 290
1
vote
0 answers

Angular controllerAs and dirty checking

When using the controllerAs syntax in AngularJS, the controller is added into the scope. But is it excluded when dirty checking is performed ? Potentialy, something changed in the controller but has no effect on the view, and nothing needs to be…
dou bret
  • 267
  • 2
  • 11
1
vote
1 answer

Accessing controller from compile function in directives

I have searched all over and the only thing I can come up with is that I don't understand something fundamental about how the compile function works. Here is what I have angular.module("app", []) .directive("foo", function(){ return { scope:…
1
vote
0 answers

How to update a variable in controller (ControllerAs syntax) from directive in Angularjs?

I have a dropzone directive: function dropzone() { return { restrict: 'C', link: function(scope, element, attrs) { var config = { url: 'http://192.168.1.114:8080/api/files', …
Harrison
  • 2,560
  • 7
  • 29
  • 55
1
vote
2 answers

How to access directive's controller variables in directive's template?

Need to use variable (defined inside the controller element of directive) in the template element. angular.module('home').directive('mediaTile', function(){ return { restrict: "AE", replace: 'true', scope: { media: '=', …
1
vote
2 answers

Angular - Filter and Delete with "Controller As" Syntax

I'm trying to learn how to write cleaner code by converting the tutorial at HERE to the "Controller As" syntax and I'm stuck on the very last step where he deletes completed "ToDos". Everything else from the tutorial works except this, nothing…
av0000
  • 1,917
  • 6
  • 31
  • 51
1
vote
2 answers

updating variable in http request callback in angular

This is probably easy but nevertheless. I have a http call in my controller where I load a json file. I want to update a variable in my html based on a result. It updates apparently the variable (console.log) in JS but not in the html. Is there a…
suMi
  • 1,536
  • 1
  • 17
  • 30
1
vote
2 answers

AngularJS - Data is not populating in table while using http service

I have a Web API which retrieves list of employees. Now when I call to $http service, I can get data from WebApi but it neither populated in table nor gives any error. Note: I am using angular v1.5.7 Below is the code I have written: HTML