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
2
votes
1 answer

Get ControllerAs alias inside base controller in AngularJS

We have legacy code written in AngularJS that does not use controllerAs. Sample Plunker Our BaseController (Plunker: script.js line 19) has this code to make all class methods available in $scope without writing this.$scope.method =…
Justinas
  • 41,402
  • 5
  • 66
  • 96
2
votes
1 answer

Why are my controllers methods not available?

after a long time I have to concentrate an angular again. But I fail... ... ng-repeat="n in DataController.getObjects" myApp.controller('DataController', [function () { console.log('test 1'); var getObjects = function () { …
2
votes
3 answers

Ways to declare Function in AngularJS Controller (controllerAs approach)

I use controller as approach instead of $scope. I have some problems with method calling from HTML. So, the question is that, how many ways exist in declare and call functions in this approach. first: (If I want to do s.th. at first) var vm= this…
Elnaz
  • 2,854
  • 3
  • 29
  • 41
2
votes
0 answers

Directive scope, calling controller functions using controllerAs and getting access to controller variables

I have a directive that loads a template and compiles it: function question($templateRequest, $compile) { return { restrict: 'E', scope: { apply: '&apply', item: '=item' }, …
2
votes
2 answers

Angularjs watch input binding change for Array when using ControllerAs

I have an AngularJs component having bindings to heroes, which is an array. How to watch this input for array changes? I tried $scope.watch("heroes", ...) and $onChanges, but didn't work so far. bindings: { heroes: '<', } Here is my plunker:…
2
votes
2 answers

populate value of id attribute from controller in template angularJs

I am writing a directive with angularJs, with a simple below html template and a contorller as c template:

Input id : {{c.inputId()}}

but the problem…
Paridokht
  • 1,374
  • 6
  • 20
  • 45
2
votes
3 answers

AngularJS: code not working when iterating through object

I am trying to populate a list of employee objects from my controller empctrl in a template. Here's the controller: app.controller('employeeController', function ($scope, employeeService) { this.employees = {}; this.populateTable =…
2
votes
0 answers

AngularJs: this instead of $scope: TypeError: this.* is not a function at *

I'm stuck with an issue when try to implement registering function for a web. Honestly, i just read some document about angularJs (and little bit about javascript) yesterday + under push. So, do not so hard to me, please :) Below is my directive: …
Lạng Hoàng
  • 1,790
  • 3
  • 17
  • 32
2
votes
2 answers

angular "controller as syntax" "this" data

I dont understand what I am missing I dont get result on html i think this problem managing with controllerAs syntax note: I can see the result in console console.log(this.movie); - its from controller app.js var app =…
ShibinRagh
  • 6,530
  • 4
  • 35
  • 57
2
votes
1 answer

AngularJS controllerAs: updating controller field in $interval does not update ng-show

I'm using the controllerAs syntax, and for some reason, when updating a controller's field in an $interval, it doesn't show/hide elements in the view properly. I use angular's UI router. The issue is best described with code I think, so please…
2
votes
1 answer

ng-show angular tab with ng-repeat

I have been working on this for a while now and cannot figure out why it will not work. This is the effect I am trying to create- http://plnkr.co/edit/RAeIwFbn2Zoe9WfLdMX8?p=preview. I wish to have create a tab bar that when clicked on will show…
2
votes
0 answers

Bind to ControllerAs Variables in Directives

Right, not an easy one to explain but I'll do my best. I'm trying to make a directive that watches/uses data from an outer-directive (both currently elements). If I don't use controllerAs syntax, this isn't an issue, as I can create a new isolated…
2
votes
1 answer

Using ng-options for select when using as notation for controller

I have a select using ng-options to define the options which works fine when I use just the controller name within the ng-controller directive. The problem is that when I add "as options" to the ng-controller it no longer works (no options). Doesn't…
2
votes
2 answers

Angular tab selecting using controller method

I am trying to use AngularJS to display the tab number when certain tab is selected using the controller method. It does not as expected. Greatly appreciate your help on this one. HTML
1
vote
0 answers

AngularJS scope is passed to directive after directive's factory function exits

I'm trying to upgrade an AngularJS template we're using to its latest version. Now, this template upgraded to AngularJS 1.6.9. But now, after i've upgraded, i'm experiencing a problem that the vm from the parent controller is recognized in the…