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
0 answers

How to unit test variables on the parent scope when using controllerAs syntax in Angular?

I'm trying to unit test a controller in which I'm using Angular's controllerAs syntax. I also use this to access variables in the parent scope. For example, if the parent controller is called parent, and the child controller called child, then in…
1
vote
1 answer

AngularJS ng-click function not reached

When I'm adding new product to a product list its not working. So the products get loaded well but the ng-click function does not getting called. (The alert I put in the addProduct function is not executed). HTML
1
vote
1 answer

Binding with service variable using ControllerAs syntax without $scope?

I'm familiarizing myself with controllerAs syntax in AngularJS, and I've come to a problem when I need to do a simple binding to a service variable. Typically a $scope.$watch or $scope.$on would do, but that would involve injecting $scope, which…
1
vote
3 answers

Using ngRoute with 'controller as' syntax in angularJS

I have the following config and controllers .config(function($routeProvider){ $routeProvider .when('/', { templateUrl: 'page-home.html', controller: 'homeController', controllerAs: 'hctrl' …
Nilzone-
  • 2,766
  • 6
  • 35
  • 71
1
vote
0 answers

Angularjs - Access parent controller without using $scope and using controllerAs

I needed a way to access the parent scope of a controller without having to inject $scope to do so. The reason behind this is that I'm building a SPA and I wanted to apply a class to the body element depending on the current page. I don't want to…
1
vote
1 answer

Angular: directive with bindToController 'loses' data

I have actionButtons directive: function actionButtons(){ 'use strict'; return { scope: {}, restrict: 'AE', bindToController: { itemId: '@', itemDescription: '@', actionsText: '@', …
1
vote
1 answer

Binding issue in AngularJS

I am trying to bind from a http get request. The http get is returning true or false. I have tested the get and it is returning properly. When I run the code below, it shows the alert(1111) properly also. However, when I'm trying to change the…
1
vote
1 answer

Angular form validation using the controllerAs syntax

I am currently facing the following problem: I would like to validate my form input using the Angular ngModel directives. When using those together with $scope they work fine. Now, working with the controllerAs syntax, they fail to work. This…
1
vote
1 answer

AngularJS controllers created with "new" or not

I've been seeing conflicting information on whether a custom controller is instantiated with a "new" keyword or simply applied to the $scope object. The documentation site says, Angular applies (in the sense of JavaScript's Function#apply) the…
0
votes
2 answers

Call angularjs directive function from controller

I've got a directive that needs to do something every now and then, let's say it has to count something. If I use the basic syntax with $scope to bind the count function, it works just fine. but when we switch to the controller as syntax it doesn't…
0
votes
1 answer

AngularJS scope variable value change not reflecting across controllers

In my angularjs, i have two controllers and use the variable which is referred in UI. From UI I am calling method OpenPage of NumTwoController which updates value of variable1 and NumOneController tries to access updated value. After I update the…
useruser00
  • 157
  • 1
  • 2
  • 14
0
votes
1 answer

Expression not working in the view that is set by a service in AngularJS

I'm quite stuck on trying to access the view with an expression that obviously fails to work. I have a Service: angular.module('myApp', []).service('myService', function($timeout){ this.sayHello = function(name) { $timeout(function(){ …
0
votes
1 answer

Unable to use controller as syntax to set up directive (scope mismatch)

I am pulling my hair out trying to get a directive called webix-ui to assume the same scope level as parent scope. This code is the closest to making webix-ui work, but the element still sees childscope. What am I doing wrong and why is my…
Vahe
  • 1,699
  • 3
  • 25
  • 76
0
votes
1 answer

Updating Property in callback with Controller As

I'm working on an AngularJS project using ES6 and Controller As syntax and running into some new issues. I have a ng-repeat which calls a function to update some data. I want the item passed to a function within ng-repeat to be updated when a…
Ryan
  • 17,511
  • 23
  • 63
  • 88
0
votes
0 answers

Communication between AngularJS controllers

I'm trying to trigger an action defined in one controller from second one. I've gone through this question, but I can't see what I am doing wrong. Here goes the code: window.cartApp = angular.module 'cartApp', ['pascalprecht.translate',…
gonczor
  • 3,994
  • 1
  • 21
  • 46