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
50
votes
3 answers

How to pass data between sibling components without using $scope?

I am making a component that contains 3 child components in this way: The main component contains list of heroes. The header component contains two buttons that are suppose to switch the view…
Beslinda N.
  • 4,808
  • 5
  • 27
  • 33
28
votes
5 answers

Using ControllerAs with a Directive

I'm trying to follow John Papa's angularJS style guide here and have started switching my directives to using controllerAs. However, this is not working. My template cannot seem to access anything assigned to vm. See this very simple plnkr…
Ryan Langton
  • 6,294
  • 15
  • 53
  • 103
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}}
7
votes
2 answers

Why can't I overwrite the value of a variable like this?

I'm trying to figure out why I'm having trouble overwriting a value passed to an angularJS directive via an isolate scope (@). I try to overwrite the value of vm.index with the following: vm.index = parseInt(vm.index, 10) However, it doesn't work…
6
votes
1 answer

memory game with angular

I'm remaking a memory game to become familiar with controllerAs View Syntax. I've narrowed the problem to the check function; but i might be wrong. The check function passes card as a parameter but when i use console.log(card) there is no value for…
user3574939
  • 819
  • 3
  • 17
  • 34
6
votes
2 answers

Using this instead of $scope inside controller

I am trying to follow style guide for angular and there wrote we should use this insted scope... Styleguide Could someone explain me when I am able to use this? Here is my try..... What I am doing wrong? I am trying to toggle form.... here is my…
4
votes
1 answer

Angular - Directive with controllerAs, bindToController, and $scope.$watch

I have a fairly straightforward AngularJS question to which I cannot seem to find an answer: How would I go about using $scope.$watch() in a directive controller while also using the controllerAs and bindToController options? Please let me know if…
4
votes
1 answer

Change a value inside ng-repeat cycle with ng-click

I want to change a value of an item inside an ng-repeat cycle using a function. This for example won't work. HTML
4
votes
2 answers

How to remove Cordova specific events outside Angular controller?

Imagine I have a controller which handles, for example, view changes: function Controller($scope){ var viewModel = this; viewModel.goBack= function(){ viewModel.visible = visibleLinks.pop(); //get last visible link …
3
votes
1 answer

using ControllerAs in an angular 1.5 component

I am attempting to use the controllerAs Syntax in an angularjs 1.5 component. here is a plunker https://plnkr.co/edit/mTa1bvoNi1Qew9l1xAFS?p=preview without the controllerAs everything works fine. (function() { angular.module("myApp", []) …
3
votes
2 answers

JavaScript | Angular | Controller As Syntax: Cannot Use `this`

Cannot Use ControllerAs this Can anyone explain the following scenario to me, please? Works ng-controller="Parent as thus" Breaks ng-controller="Parent as this" That single letter which makes it a keyword -- which I want -- wrecks the forest. Why…
Cody
  • 9,785
  • 4
  • 61
  • 46
3
votes
2 answers

Calling sub function in ControllerAs AngularJS

Hey I am new to angularjs Im using controlleras style in angularjs as the code is presentable and net. My problem is calling subfunction in controller my code as follow //AngularJS CODE (function(){ 'use strict'; …
jake talledo
  • 610
  • 11
  • 24
3
votes
2 answers

AngularJS expression not evaluating

I am a beginner in AngularJS and I am currently around with the basics. I am trying to create a simple menu but I have a couple of Angular expressions that aren't evaluating; {{ dish.description }} and {{ dish.comments }}. I tried to debug the page…
3
votes
1 answer

Trouble with Angular Nested Directives when using ControllerAs

I am building a huge form that calls various directives to build a complete form. The Main Page calling the Form Builder passes the ng-model data like this:
Then the Form Builder Page calls various…
3
votes
2 answers

AngularJS ControllerAs syntax and controller injected variables

I'm writing a directive and trying to stick to the John Papa style guide. So I've also decided to jump on the ControllerAs syntax wagon and I've got a tiny directive like below: (function() { angular .module('htApp') …
1
2 3 4 5 6 7 8