Search Posts

Category: javascript

How do I convert ISO date format to yyyy-MM-dd format using momentjs or vanilla JS?

I’m trying to hit a soccer sports API which includes date in the format of yyyy-mm-dd, only the scores from that date to current date will be displayed. The current date is chosen by user using a calendar but when the user chooses the date from calendar, it gets displayed in ISO format as “Fri Aug 17 2018 00:00:00 GMT +0545 (Nepal Time)” . I want to convert this date in the front end in […]

AngularJS Binding Data

So i have a productList and cart where i store products, when i add product to cart(localStorage), products count must async refreshed, but it refreshed only with refreshing a page (this is about goodsInCart). Maybe it needed to adding EventListener? Please tell me where i was wrong. products.html <div ng-controller=”ProductController”> <div class=”container”> <h1 class=”page-header”>Product List</h1> <div class=”small-cart”> <a href=”#!/cart”> <span class=”amount”>{{goodsInCart}}</span> <img class=”cart” src=”./images/cart_2.png”> </a> </div> <div class=”row”> <div class=”item col-sm-6 col-md-4 col-lg-3″ ng-repeat=”product in […]

Use Laravel and Angularjs Routing at once

I am working on an E-Commerce WebApp. In which I am using Laravel for the backend and Angularjs for the front end. But the problem it when I click on specifc navigation item it will work fine but when I reload the page,It will go for laravel routing and all me css, js, images etc. will not loaded properly. Laravel Code : Route::get(‘/’, function () { return view(‘index’); }); Route::get(‘/dashboard’, function () { return view(‘dashboard’); […]

how to put ng-show conditions in a function in .js file

I am trying to validate a webpage where the inputs will be alphanumeric, max-length is 45 and unique. Here is the code. Is there any way that I could put all these three ng-show conditions in one function in my controller.js (something like $scope.showError ()) and only call that function in ng-show here form name=”addFieldForm” .w-100 .pv3.w-100.w-two-thirds-ns label What type of field would you like to add to your input? select name=”type” ng-model=”field.type.value” ng-options=”type.value as […]

AngularJS filter refresh for placeholder

I am using filter to localize my page. AngularJS filters only refresh when the key is changing unless they are expressions (or objects) and then they are evaluated on every digest cycle. So instead of writing this: <div>{{‘name’ | localFilter}}</div> I used a little trick and wrote the ‘name’ as expression to trigger filter refresh on every digest cycle. I defined variable localize=true <div>{{localize && (‘name’ | localFilter)}}</div> and it worked. BUT it doesn’t […]

How to retrieve angularjs cachefactory.get values

I am storing data to $cacheFactory as such: $scope.loginCache = $cacheFactory.get(‘login’) || $cacheFactory(‘login’) ; $scope.loginCache.put(“smsData”,$scope.smsData) ; And later am retrieving it with: $scope.loginCache = $cacheFactory.get(‘login’) || $cacheFactory(‘login’) ; $scope.smsData = $scope.loginCache.get(‘smsData’) ; However, I am unable to access the various elements of $scope.smsData. Out putting it to console.log does show all the values there but for some reason I am unable to access the data – what am I doing wrong? console.log($scope.smsData) ; // displays […]

AngularJS ng-hide/show label/button if length(description) < 20

I need to show/hide label if length(description) < one row. Code is working ok, but if length < one row, label isn’t hide. How to hide/show label? If [[ demandAd.description ]] less than one line or less than one row(or length < 100), I need to hide label because it doesn’t have a function at that time <div class=”demand”> <p class=”demand-ad-time”>[[demandAd.createdAt | date:”dd.MM.yyyy.”]]</p> <input type=”checkbox” class=”read-more-state” id=”demandAd[[ ]]” /> <p>[[ demandAd.description ]]</p> <label for=”demandAd[[ […]

How to set multiple baseURL using restangular in angularjs

below code is my app.js file, and my problem is i have declared multiple port number(base URL) its working fine. app.config(function (RestangularProvider) { RestangularProvider.setBaseUrl(‘http://localhost:8086/mmg/api/v1/’); RestangularProvider.setDefaultHeaders({ “X-API-KEY”: “MMGATPL”, “Content-Type”: “application/json”, }); }); app.factory(‘FirstRestangular’,[ ‘Restangular’,function (Restangular) { return Restangular.withConfig(function(RestangularConfigurer) { RestangularConfigurer.setBaseUrl(‘http://localhost:8085/mmg/api/v1/’); RestangularConfigurer.setDefaultHeaders({ “X-API-KEY”: “*******”, “Content-Type”: “application/json”, }); }); }]); How should i declare base URL in route.js app.config(function (RestangularProvider, $stateProvider, $urlRouterProvider) { RestangularProvider.setBaseUrl(‘http://localhost:8086/mmg/api/v1/’); }; I can set only one base URL, if i declared multiple URL its […]

How to check chain of hasOwnProperty in objects

I have json like this var a = { “name”: “test1”, “redisData”: { “redisIp”: “”, “dbSetting”: { “dbIp”: “”, “dbUserName”: “root”, “dbUserPassword”: “root”, }, “otherData”:{ “email”:”[email protected]” } } } So i have to push this data in database when all the data present in all key for that purpose i have to validate that data like this if (a.hasOwnProperty(“redisData”)) { if (a.redisData.hasOwnProperty(“dbSetting”)) { if (a.redisData.dbSetting.hasOwnProperty(“dbIp”)) { if (a.redisData.dbSetting.dbIp) { // now insert in to database […]

Next Page »