angularjs-controller

Angular: Dependency Injection with prototypal inheritance

雨燕双飞 提交于 2019-12-11 10:44:01
问题 According to Todd Motto's styleguide, Controllers chapter: Inheritance : Use prototypal inheritance when extending controller classes I try to implement it in my controllers: function BaseController(){ 'use strict'; this._path = ''; this._restService = undefined; } /** * Boring JSDocs */ BaseController.prototype.getById = function(id) { return this._restService.getById(this._path, id); }; TagModalController.prototype = Object.create(BaseController.prototype); /** * Even more boring JSDocs */

How to go back to previous page without refreshing in angularjs?

眉间皱痕 提交于 2019-12-11 10:35:03
问题 I currently have an AngularJS application with routing built in. It works and everything is ok. where i have 2 controller. in first controller i have a button when i click button 2nd controller will run. when i try to go back or history.back() the 1st controller is again executing. how to prevent it? 回答1: angularjs will always execute controllers when ever page is get redirected from one page to another page if you written controller as page specific. If your application is SPA then you can

AngularJS - dynamically load templateURL when passing object into attribute

↘锁芯ラ 提交于 2019-12-11 09:14:47
问题 In my controller HTML I am passing an object into a directive as such: <div cr-count-summary countdata="vm.currentCountData"></div> The vm.currentCountData is an object that is returned from a factory My directive code is below: function countSummary() { var directive = { scope: { countData: '=' }, link: link, templateUrl: function(element, attrs) { if (attrs.countdata.type === 'Deposit') { return 'app/count/countsummary/countDeposit.html'; } else { return 'app/count/countsummary

Controller loaded by ng-include not working

守給你的承諾、 提交于 2019-12-11 07:50:02
问题 I have a page with a pop-up I use on several pages and I load it using ng-include. In this pop-up there is three tabs also dynamically loaded using ng-include. So my code looks like this: <div ng-include="'/pages/ng-templates/Cockpit.html'"></div> in Cockpit.html I have the following code: <div id="dlgCockpit" class="Cockpit jquerydialog"> <div id="tabs"> <ul> <li><a href="#tabA">tabA</a></li> <li><a href="#tabB">tabB</a></li> <li><a href="#tabC">tabC</a></li> </ul> <div id="tabA"> <div ng

Adding directive inside the directive programatically

妖精的绣舞 提交于 2019-12-11 03:56:52
问题 I want to append another instance of my directive into the parent directive but i can't use $apply to recompile my directive. I think i miss something here somewhere :) My HTML Code <div ng-app="TestApp"> <div ng-controller="TestCtrl"> <input ng-model="NewData" /> <button ng-click="AddNewData($event)">Add New</button> <br /><br /> <div test-collector="testColScope" id="testCol"> <div test-data="" xx-value="Mouse" xx-href="https://fb.com"></div> <div test-data="" xx-value="Keyboard" xx-href=

AngularJS sharing data between factory & controller across modules

↘锁芯ラ 提交于 2019-12-11 03:16:24
问题 I have an angularjs app that has several modules. The main modules looks something like: var app = angular.module('mainMod', ['apiService']); app.controller('MainCtrl', function (Socket) { $scope.objects = {}; // do something with $scope.objects, etc. }); And then I have; var apiService = angular.module('apiService', ['ngResource']); // etc and; apiService.factory('Socket', ['$rootScope', function ($rootScope) { // create a websocket and listen for stuff // if something happens, update

Does polluting the $scope object affect performance?

狂风中的少年 提交于 2019-12-11 02:48:30
问题 I have a controller where the $scope object has been used to store methods and values that are only used locally within the same controller. There is a lot of this going on: $scope.foo = 'something'; $scope.bar = 'something else'; ... and so on. None of these values are used within the view. My question is does polluting the $scope object affect performance? Is it a good idea to clean this up so only values and methods needed for the view are contained in the $scope object? 回答1: Yes,

Why controller doesn't respond on route update?

萝らか妹 提交于 2019-12-11 01:38:02
问题 I would like preserve instance of controller without reloading. I set reloadOnSearch to false and I manage route change in my controller. Here is the code. This is example of my link <a href="products/page/2">next</a> . I have defined following module. angular.module('app.products', ['ngRoute', 'ngResource']) .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/:section/:view/:number', { templateUrl: 'tpl/table.html', controller: 'ProductsCtrl', controllerAs:

TypeError: api.getAll is not a function, service method is not recognized

大憨熊 提交于 2019-12-11 00:31:55
问题 I have a very simple service and a controller attempting to get some information from it, but I keep getting .methodName is not a function. Here is the service, apiService.js : (function (module) { function api() { var sharedService = {}; sharedService = { getAll: function () { return 'test'; } }; return sharedService; } module.factory("api", api); }(angular.module("anbud"))); Then I attempt to use my method getAll in the controller, like this: (function () { 'use strict'; angular.module(

AngularJS : Scope issue in $http success callback

偶尔善良 提交于 2019-12-10 20:25:23
问题 I'm using PHP to get data into my factory, which shows correctly in the success callback function within the controller. However, even after assigning the returned data to $scope.customers, it's not there if I do a console.log($scope.customers) after the callbacks, and my view's [ng-repeat] isn't picking it up either. Any idea why the scope of my data would be restricted to just inside the success callback if I'm assigning the returned data to my $scope object? var customersController =