angularjs-controlleras

Using ngRoute with 'controller as' syntax in angularJS

那年仲夏 提交于 2020-01-07 03:24:08
问题 I have the following config and controllers .config(function($routeProvider){ $routeProvider .when('/', { templateUrl: 'page-home.html', controller: 'homeController', controllerAs: 'hctrl' }) .when('/about', { templateUrl: 'page-about.html', controller: 'aboutController', controllerAs: 'actrl' }) .when('/contact', { templateUrl: 'page-contact.html', controller: 'contactController', controllerAs: 'cctrl' }); }) .controller('homeController', function(){ this.pageClass = 'page-home' })

using ControllerAs in an angular 1.5 component

女生的网名这么多〃 提交于 2019-12-22 10:03:09
问题 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", []) .component("helloWorld", { template: "Hello {{$ctrl.name}}, I'm {{$ctrl.myName}}!", bindings: { name: '@' }, controller: helloWorldController }) function helloWorldController() { /* jshint validthis: true */ var vm = this; vm.myName = 'Alain' } })(); however

AngularJS: code not working when iterating through object [duplicate]

自作多情 提交于 2019-12-18 09:33:49
问题 This question already has answers here : 'this' vs $scope in AngularJS controllers (7 answers) Closed 3 years ago . 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 = function (data) { this.employees = data; }; var error = function (err) { console.log("Error: " + err); }; // Call Service to List all Employees

Ng-Click not firing

隐身守侯 提交于 2019-12-13 01:07:00
问题 whenever I click my submit button nothing happens, currently all I want it to do is print out the username and password to test there bindings. And I am able to talk to the controller and print out hard coded message that I made in the controller, it seem's that the ng-click doesn't fire on that method. Any help would be great, Thanks :D <section id="register-view" class="mainbar"> <section class="matter"> <div class="container"> <div class="row"> <label>{{vm.message}}</label> <form class=

Extend Angular controllers using controllerAs syntax & prototypical inheritance

别等时光非礼了梦想. 提交于 2019-12-12 02:24:45
问题 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.module('myApp').factory('BaseController', function() { var BaseController = function(fooService, barService) { // base controller constructor logic } BaseController.prototype = { // base controller methods } return BaseController; }); Then use it like so: var ChildController = function

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

 ̄綄美尐妖づ 提交于 2019-12-10 16:18:58
问题 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"> <span>{{todo.name}}</span> <button ng-click="example(todo)">Change me</button> </li> </ul> JS $scope.example = function(v) { v.name = 'i am different now'; }; Full example http://plnkr.co/edit/kobMJCsj4bvk02sveGdG 回答1: When using controllerAs pattern, you should be using controller alias while accessing any variable

Using controller inside another controller in AngularJS

[亡魂溺海] 提交于 2019-12-04 20:06:18
问题 Why I can't bind to controller's variable inside second controller? <div ng-app="ManagerApp"> <div ng-controller="MainCtrl"> Main: <div ng-repeat="state in states"> {{state}} </div> <div ng-controller="InsideCtrl as inside"> Inside: <div ng-repeat="state in inside.states2"> {{state}} </div> </div> </div> </div> var angularApp = angular.module('ManagerApp', []); angularApp.controller('MainCtrl', ['$scope', function ($scope) { $scope.states = ["NY", "CA", "WA"]; }]); angularApp.controller(

AngularJS: code not working when iterating through object [duplicate]

冷暖自知 提交于 2019-11-29 17:15:28
This question already has an answer here: 'this' vs $scope in AngularJS controllers 7 answers 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 = function (data) { this.employees = data; }; var error = function (err) { console.log("Error: " + err); }; // Call Service to List all Employees console.log("Service called to populate table."); employeeService.output().then(this.populateTable, error); this.populateTable();

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

天大地大妈咪最大 提交于 2019-11-29 12:51:57
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 is this? P.S. I'm aware of the vm convention, but I find it disturbs portability of controllers/viewmodels. The problem is certainly not that this is a reserved word in JavaScript. There is no rule in the controller as syntax that says you would need to assign the value of this to a variable with the same name as the controller and I'm pertty sure

Using ControllerAs with a Directive

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 23:02:29
问题 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 example that exhibits the behavior. http://plnkr.co/edit/bVl1TcxlZLZ7oPCbk8sk?p=preview angular .module('app', []); angular .module('app') .directive('test', test); function test() { return { restrict: 'E', template: '<button ng-click="click">{{text}}<