angularjs-scope

Using ng-change in AngularJS with “Controller As” syntax

泪湿孤枕 提交于 2019-12-12 03:36:19
问题 I am trying to avoid using $scope in my controller function, instead opting to use var viewModel = this; with "controller as" viewModel syntax. My problem is that I need to use ng-change to call a function in my controller but while I am able to access data from a service, I am unable to call functions. //Controller (function () { 'use strict'; angular .module('app') .controller('GeneralSettingsController', GeneralSettingsController); GeneralSettingsController.$inject = ['SimulationService'];

Add Directive Attribute to Directive Element

大城市里の小女人 提交于 2019-12-12 03:33:13
问题 I have a directive element: return { restrict: 'E', replace: true, transclude: true, template: '<ul>' + '<li {{myNewAttrDirective}}>Home</li>' + '<li {{myNewAttrDirective}}>Products</li>' + '<li {{myNewAttrDirective}}>Cart</li>' + '<li {{myNewAttrDirective}}>Contact Us</li>' + '</ul>', scope: { _showMore : '=showMore' }, link: function(scope, element, attrs) { if (scope._showMore === true) { scope.myNewAttrDirective = 'myAnimationDirective' } } }; HTML: <my-directive show-more="true"></my

Generic error handling in Angular

白昼怎懂夜的黑 提交于 2019-12-12 03:31:57
问题 I am using interceptor in my app for generic error handling when service is down I am getting success response with status 200 even i have changed the base url to test my service. What am i doing wrong?? var myServices = angular.module('myServices', ['ngResource']); myServices.config(function ($provide, $httpProvider) { $provide.factory('ErrorInterceptor', function ($q) { return { response: function(){ return response;// always success?? } responseError: function(rejection) { $scope

Display all days(dates) between two dates in angularjs

随声附和 提交于 2019-12-12 03:26:01
问题 I want to use select " From " and " To " dates from datepicker and display all dates in between, in tabular form using angularjs. 回答1: Try this function to calculate no. of days. Hope it helps function daysCalculator(date1, date2) { var d1 = new Date(date1); var d2 = new Date(date2); var days = d1.getTime() - d2.getTime(); days = parseInt((((days / 1000) / 60) / 60) / 24) return days; } 回答2: Try using this. function getDates(fromDate, toDate) { var dateArray = []; var nextDate = fromDate;

Accessing a directive's scope variable from another directive

青春壹個敷衍的年華 提交于 2019-12-12 03:23:21
问题 I've created a directive that binds the pageYOffset to a scope variable on window scroll like this: app.directive('scrollDirective',function(){ return { restrict: 'E', link: function(scope,elem,attrs){ angular.element(window).bind('scroll',function(){ scope.watchScroll = pageYOffset; }) } } }) And I am trying to access watchScroll variable from another directive like this: app.directive('anotherDirective',function(){ return { restrict: 'A', link: function(scope,elem,attrs){ scope.$watch

How to remove undefined error in angular js?

烂漫一生 提交于 2019-12-12 03:17:25
问题 How to remove undefined error in angular js ?Actually i am trying to load data in using resolve and use that data in controller but on controller i am getting undefined why ? resolve: { message: function (testservice) { return testservice.getdata(); }, message2: function (testservice) { return testservice.getTodo(); }, message3: function (testservice) { return testservice.getGithub(); } } use the controller .controller('b', function($scope, $stateParams, $state, $ionicHistory,message) {

How to access scope in a function inside link function in angularjs directive?

邮差的信 提交于 2019-12-12 03:17:02
问题 This might not be an angularJS problem but I am at my wit's end here. The code is shown below: prep.directive('resultgraph', function () { return { restrict: 'A', link: function (scope, element, attrs) { //** scope accessible here ** DomReady.ready(function () { ThreeBox.preload([ '/scripts/lib/snippets.glsl.html', ], function () { //....scope not accessible here How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ? 回答1: If you need

Route resolving + multiple controller combo?

我们两清 提交于 2019-12-12 03:16:40
问题 I'm trying to combine 2 concepts and I'm having trouble making them work together. Concept 1 : Route resolving. This is easy to explain, I just want to resolve certain models like this: $routeProvider .when("/news", { templateUrl: "news.html", controller: "newsCtrl", resolve: { news: function(Model) { return Model.news.getList(); } Concept 1 : The idea of a 'base controller' that I can use in the route controller: xyz , then in the actual view html I load the 'sub' controller. For instance...

Angularjs performance

北慕城南 提交于 2019-12-12 02:58:46
问题 I have a project that needs a good performance with a large number of records showed. My data structure: SERVERS (+- 15 per page) WEBSITES (+- 20 per server) USERS logged in with your STATUS (+- 500 per website) What is the best approach for my Objects and Controllers? One Controller with one neasted object. ServerCtrl -> $scope.Server[0].Websites[0].Users One Controller with three lists ServerCtrl -> $scope.Servers; $scope.Websites; $scope.Users Three Controllers with three separated lists

Angularjs: When page loads, (for the first tab) trigger the method that is normally triggered by ngClick on a button

柔情痞子 提交于 2019-12-12 02:29:17
问题 This is related to a tabbed interface for displaying timelines/posts from different social networks. Everything is fine, I have a sidebar with vertically tiled tabs. Click on a tab will make a call to the resource and load that tab (social network)'s posts. ng-click="loadTabContent('network')" The issue is that on page load no tab has content displayed, whereas I'd like the first one to be already loaded (obviously). I assume I need to somehow trigger that very same method when page loads and