The angularjs-controlleras tag has no usage guidance, but it has a tag wiki.
1
vote
1answer
29 views
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 "" $...
18
votes
3answers
18k views
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 ...
0
votes
2answers
31 views
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: '...
-1
votes
2answers
43 views
What is key benefits of using controllerAS in angularJS
ng-controller="invoiceController as invoice" create new invoiceController constructor and assigned the same to scope behind the scene, which the similar thing $scope injection does in controller ...
33
votes
3answers
19k views
How to pass data between sibling components without using $scope?
I am making a component that contains 3 child components in this way:
<header-component>
<side-component>
<main-component>
The main component contains list of heroes.
The header ...
1
vote
0answers
41 views
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 ...
0
votes
1answer
30 views
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", [])
....
0
votes
0answers
38 views
IE : Angular Controller As losing scope when there is error in other JavaScript library
I am using the ControllerAs syntax in AngularJs. The issue I am facing is that there is an error being thrown by the jQuery library when other javascript library calls the jQuery which is run parallel ...
0
votes
1answer
30 views
Directive Parameter Not Initializing on First Load In AngularJs
I'va made a Dropdown directive, i'm trying to assign methods on passing parameter to directive and i'll call these method from controller.
but on first load i'm not getting the assign method in ...
1
vote
0answers
33 views
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....
2
votes
1answer
44 views
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');
...
0
votes
2answers
53 views
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",
...
0
votes
2answers
59 views
AngularJS Ctrl As Syntax with Services
I'm migrating my Angular 1.x code to use the newer, more preferred syntax of avoiding using $scope and using the controller as syntax. I'm having an issue with getting data from a service though.
...
1
vote
2answers
42 views
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 ...
0
votes
1answer
59 views
Multiple directives in same element operating on visibility
I have been struggling with my approach for the following scenario.
I have a custom directive authorize where I pass the name of a group. If the current user has this group in his profile then the ...
1
vote
0answers
139 views
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: '&...
6
votes
1answer
92 views
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 ...
2
votes
1answer
2k views
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 ...
1
vote
2answers
36 views
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 (...
0
votes
1answer
29 views
AngularJS variable does not persist to view
Having a strange bug here, I can succesfully switch to other views but my problem is that even a simple variable cannot "reach" the views. Does anyone see my (probably stupid) mistake?
Index.html
&...
1
vote
2answers
241 views
Mixing ControllerAS with $scope
For all new work I use the ControllerAs syntax so that I can refer to the controller as vm within my views. Which is great.
However I still a large portion of old code that uses the $scope syntax. ...
4
votes
2answers
674 views
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 ...
0
votes
0answers
32 views
Share data b/w parent controller and directive with ControllerAs
I was going through the differences b/w $scope and ControllerAs and stuck at one thing.
If using $scope in parent controller,I can share data by creating my custom directive's scope as shared,...
1
vote
2answers
85 views
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 ...
0
votes
0answers
23 views
Variables null between functions controllerAs [duplicate]
i'm kinnda new in AngularJS. I'm trying to make a controllerAs controller:
var vm = this;
vm.accounts = [];
vm.authorized = false;
vm.title = 'LoginPage';
A function which i use to ...
1
vote
1answer
28 views
Create a variable inside ng-repeat generated scope (using controllerAs syntax)
<tbody id="table">
<tr data-ng-repeat="consulting in consultingsVm.consultings">
<td>
<a href="" class="mode mode--edit"
...
1
vote
2answers
130 views
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....
1
vote
1answer
206 views
Directive with it's own controller placed within ngAnimateSwap results in new controller being initialized on every 'swap'
I have created a directive (ParentDir) that has it's own controller and whose template binds to this controller. It communicates with another directive (Child1) that has it's own controller which '...
0
votes
4answers
315 views
Angular watch doesn't work with controllerAs syntax
Have a problem with watching response.
I have a SettingsCtrl as settings and this is my view:
<input type="text" class="form-control" ng-model="settings.test.one" />
<input type="...
1
vote
2answers
94 views
Refreshing ng-repeat without $scope, without new request to sever
I have a table with this content:
<tbody>
<tr ng-repeat="result in ctrl.result track by $index">
<td ng-bind="$index+1"></td>
<td ng-bind="::result....
0
votes
0answers
123 views
AngularJS Directives and ControllerAs jasmine test
I'm trying to test a directive with jasmine, but the controller is always undefined.
angular.module('test.app').directive('testDirective', tDirective);
function tDirective() {
myController.$...
-1
votes
3answers
1k views
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.
...
0
votes
0answers
69 views
Make an object for angularJS controller using $resource (factory|service)?
My approach is using AngularJS Service instead of factory along the project. Now I want to build an object called MyData which should be used as array in angularJS controller, such as:
vm.datas= ...
0
votes
2answers
102 views
Have a dynamic html element using AngularJS Directive WHITOUT $scope?
I want to use This Plunker sample code to add some elements dynamically to HTML page using AngularJS. (You should run It in a new link, not in editor environment) This is my first experience in ...
1
vote
3answers
78 views
Is there really no difference between AngularJS $scope and Controller as syntax?
I am learning angularJS and while learning found the controller as syntax much easier to read and a little easier for me coming from the OO world to understand. I have read several articles and SO ...
1
vote
3answers
91 views
Shared variables and multiple controllers AngularJS
I have multiple controllers on a small app I'm writing, and I have successfully shared a 'selected' variable between the controllers like so.
app.service('selectedEmployee', function () {
var ...
1
vote
2answers
421 views
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.
...
2
votes
2answers
61 views
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
(...
2
votes
2answers
383 views
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 }} ...
2
votes
2answers
66 views
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:
<p>Input id : {{c.inputId()}}</p> <!--this is for test,correct value is ...
1
vote
1answer
84 views
Angular app with ui-router not hitting controller unless its inline function
I am having trouble with ui-router. If I use an inline function it works, otherwise when I click on the route the controller is not used. I can debug the browser and the js is being delivered but no ...
1
vote
1answer
199 views
angular directive controlleras and link
I have markup like this
<i class="fa-font icon-user" wd-user-profile></i>
to show / hide this div
<div id="user-profile" ng-show="vm.isVisible">
<h3>user name</h3>
...
3
votes
2answers
322 views
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() {
...
4
votes
1answer
804 views
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
<ul class="unstyled">
<li ng-repeat="todo in todoList.todos">
&...
1
vote
3answers
109 views
AngularJS: code not working when iterating through object [duplicate]
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) {
...
1
vote
0answers
118 views
(Angular) Passing instance of controller to isolate scope
While the code below "works", it definitely feels very wrong. Is there a "best practices" way to refactor? The issue is that I'm passing an instance of the controller into an isolate scope directive
...
0
votes
1answer
53 views
Angular JS using controllerAs and this syntax with scope or this variables
There is a problem I have always run into and its resulting into inconsistency with the definition of controller scope variables.
As you might be aware that using controllerAs syntax you have to ...
0
votes
1answer
88 views
Pass $scope data from controller to view
I want to display $scope.predicate and $scope.reverse values into my view(in the <p> tag ). It seems that using {{ }} expression is not working.
app.js:
var app = angular.module('testApp', [])...
0
votes
1answer
33 views
Angular controller functions are both constructors and a decorators?
If one writes a controller as ctrl for the following code:
function Controller($scope) {
$scope.abc = "123";
}
angularApp.controller("controller", Controller);
Does the pseudo code below ...
0
votes
1answer
151 views
Extend Angular controllers using controllerAs syntax & prototypical inheritance
I'm trying to extend controllers using conrollerAs syntax.
My parent and child controllers are not defined in the same scope, so I put the parent controller (BaseController) in a service:
angular....