Search Posts

Category: javascript

How to postpone angular expression evaluation after an asynchronous operation in Angular 1?

How do I postpone the evaluation of angular expressions in the HTML after an asynchronous operation? I need the translate function that only becomes defined after an AJAX call. Here is the code: angular.module(‘app’, []) .run([‘$rootScope’, ‘$http’, function($rootScope, $http) { $rootScope.locale = ‘en’; $http.get(‘/resources’).then(response => { let dictionary =; $ = (key, …args) => { let text = dictionary[$rootScope.locale][key]; args.forEach((value, index) => text = text.replace(`{${index}}`, value)); return text; }; }); } In the HTML, […]

high light latest file while uploading document and scroll bar should be move as per document

i am trying to achieve the functionality of move scroll bar as per new upload, when i am uploading any document at that time i am high lighting that document,suppose i have 20 document in my list then i am uploading 21th document that time scroll bar should move to that document means it should move as per new document,currently i am showing latest document through high lighting but scroll bar is not moving,if somebody […]

Why interval not work after ng-click?

I don’t know why after I click button but interval not work in HTML. I use angularJS to get count in every second. I just want interval start after click button. This HTML <button type=”button” ng-click=”start()”><span>Start {{hitung}}</span></button> And this JS $scope.hitung = 0; $scope.start= function () { var auto = $interval(function () { $scope.hitung++; }, 1000); }; I try this but interval not work and $scope.hitung always 0. If any one have solution please tell […]

Cannot refresh view, both reload solutions I’ve found have crashed instead

I have created widgets from facebook and twitter. Because I’m using ui-router for my routing the script tags are in the index.html and the actual html is in my leagues.html file. So, when I first load the page the fallback shows ‘Tweets by …’. But if I were to refresh the page the widgets show up correctly. The solution I’d like to use is to automatically refresh the page every time I go to ‘app.leagues’. […]

Running angular project from Visual Studio Code results in ‘This site can’t be reached’ error

I followed the tutorial here: vs-angular-tutorial However after I added the chrome config to my launch.json file and hit f5 aI was met with a ‘this site can’t be reached’ error instead of the webpage. I did look into this a bit and if I run ‘npm start‘ or ‘ng serve’ in the folder before hitting ‘F5’ it loads correctly. Is this expected behaviour? There is no other way to jus tmake it work without […]

Submit array data with ng-submit get error Cannot read property ‘name’ of undefined

I want to submit a form with array data <form ng-submit=”processForm()”> <div class=”item item-text-wrap item-toggle” ng-repeat=”item in items | orderBy: [‘id’,’name’]”> {{}} <label class=”toggle toggle-calm”> <input type=”checkbox” ng-model=”formData[$index].id” ng-true-value=”{{}}” /> <div class=”track”> <div class=”handle”></div> </div> </label> </div> <div class=”item”> <button class=”button button-block button-calm”>Submit</button> </div> </form> In controller: .controller(‘ProcessCtrl’, function ($scope, $http, $localStorage, $state) { $scope.formData = []; $scope.processForm = function () { $http({ method: ‘post’, url: ‘process.php’, data: $.param($scope.formData), headers: {‘Content-Type’: ‘application/x-www-form-urlencoded’} }) .success(function (result) […]

Samsung keyboard cursor position issue JS setSelectionRange

This angular directive auto-inserts commas every three digits in number input fields (e.g. “1000” becomes “1,000”). It preserves cursor position correctly in all browsers I have tested, except on Samsung phones with the Samsung keyboard, for example the Galaxy S8 running Android 7.0, Samsung experience version 8.1. On Samsung, if I type “1000”, the comma is inserted, and my cursor ends up between the tens and ones position, when it should be all the way […]

Return an array from a function with a promise

I need to return the array lotSpecItems from this function once it is populated: public getLotSpecItems(id: number) { let toReturn = this.resourceClass.getLotSpecItems({ lotId: id }); let lotSpecItems = []; return toReturn.$promise.then(lotSpecItemsArray => { lotSpecItemsArray.forEach(lotSpecItem => { lotSpecItems.push(this.$di.logicFactory.getLotSpecLogic().mapLotSpecItem(lotSpecItem)); }); }); } The $promise is an angular js promise: (property) angular.resource.IResourceArray<any>.$promise: ng.IPromise<ng.resource.IResourceArray<any>> Client code (can be edited to not expect a promise): $onInit() { this.lotLogic.getLotSpecItems( => { this.searchResults = results; console.log(this.searchResults); }); It currently returns undefined. What […]

how to delete a cookie if the browser crashes

I have a situation in my application where the users should are not allowed to open multiple instances of the application in a browser. So we are reading the cookies, if there is a session already opened we alerting the user that they are attempting to open multiple sessions. Some times if the browser crashes for some reason the browser is still having the old cookie and when the user is attempting to open the […]

Passing user input into $http.get request angularJS

I am currently trying to pass user input into my $http.get request. I am using bootstrap and angular but am confused as I have am trying to pass two dates through a bootstrap modal. I currently have a controller like this app.controller(‘testCtrl’, function($scope, $http){ $http.get(“website” + box1 + box2).then(function(r){ $scope.Data =; }); }); And a modal in bootstrap with <div class=”modal-header”> <h4 class=”modal-title”>test</h4> </div> <div class=”modal-body”> <input id=”box1″ type=”text”/> <input id=”box2″ type=”text”/> </div> <div […]

Next Page »