Angular.JS

Angular.JS

+ Follow 1,256 Followers

Share

IT Courses > Web Development > Angular.JS

Angular.JS Lessons

Features of Angular JS:
Data Binding Structural Programming TDD Support Parallel Development Routing for SPA Dependency Injuction Client Side State Managment Product of Google

Srikanth | 25 Jan

0 0
0
Angular Material
What is Angular Material? For developers using AngularJS, Angular Material is both a UI Component framework and a reference implementation of Google's Material Design Specification. This project provides...

Monisha N. | 24 Jan

0 0
0

Trending Discussions

V

Show previous answers

R

Real Time Signals India Pvt Ltd | 2 days ago

Generally it should cost around Rs. 20,000/- inc. of tax

Suprio Dutta | 2 days ago

Student level projects are at affordable rates.

S

Show previous answers

Rohit Kumar Srivastava | 12 Feb

Routing is used for traverse the page from one to another with customize it .

John Paul | 6 days ago

Routing is anything and everything to do with: Where to go, What to do while going, What should be shown, Where should it be redirected. Based on various factors like Is the user allowed to see the page, etc.

H

How would you make an Angular service return a promise please explain this one with a example?

0 4

Show previous answers

John Paul | 6 days ago

Working With Promises in AngularJS Services. Let's talk about working with promises in AngularJS. To start, $q is a great implementation of promises, allowing you work with deferred objects and be more efficient with Ajax calls. $q api has few useful methods, first one is to create new deferred object using $q.defer(), so this object could be resolve in the future using $.q.defer().resolve and also to be reject using $.defer().reject methods. Explore Angular Courses When executing Ajax calls from AngularJS services, usually we use $http which return by default a promise object which we can attach â??thenâ?? method to for result notification. But when the service should fetch data from the backend and allow more than one AngularJS controllers to use, it doesnâ??t make the make the most sense to fetch everything from the server every time. Then, we should save the data in local variable inside the service. So when the AngularJS controller calls the service api to get the data, it could be a promise from the Ajax call or the data stored from previous call. The AngularJS controller should be able to differentiate between the cases, so thats not an ideal practice. The way of doing it is to wrap the data stored in AngularJS service with another $q api called $q.when which can treated as a promise for both cases, so when the $q.when receive a promise it will be resolved when the promise will and if it receive a real data it will be resolved immediately. That is transparent to the controller and this is a good practice. Hereâ??s a full code snippet below based on the above overview. (function() { 'use strict'; angular .module('testApp') .service('testService', testService) .controller('testCtrl', testCtrl) .controller('testCtrl2', testCtrl2); function testService($http, $q) { // will hold backend posts var posts = undefined; // fetch all posts in deferred technique this.getPosts = function() { // if posts object is not defined then start the new process for fetch it if (!posts) { // create deferred object using $q var deferred = $q.defer(); // get posts form backend $http.get('http://jsonplaceholder.typicode.com/posts') .then(function(result) { // save fetched posts to the local variable posts = result.data; // resolve the deferred deferred.resolve(posts); }, function(error) { posts = error; deferred.reject(error); }); // set the posts object to be a promise until result comeback posts = deferred.promise; } // in any way wrap the posts object with $q.when which means: // local posts object could be: // a promise // a real posts data // both cases will be handled as promise because $q.when on real data will resolve it immediately return $q.when(posts); }; } function testCtrl($scope, testService) { $scope.getPosts = function() { testService.getPosts() .then(function(posts) { console.log(posts); }); }; $scope.getPosts(); } function testCtrl2($scope, testService) { $scope.getPosts = function() { testService.getPosts() .then(function(posts) { console.log(posts); }); }; $scope.getPosts(); } })(); credit: appendto.com

Paniraj N | 2 days ago

using$q you can return a promise. for ex. if you have a function called updateProduct in the ProductService you can do as below var _updateProduct = function (product) { var deferred = $q.defer(); $http.defaults.useXDomain = true; $http({ url: baseUrl + 'api/product/', method: "POST", data: product//, headers: { 'Content-Type': 'application/json; charset=utf-8' } }).success(function (modifiedProduct) { deferred.resolve(result.data); }).error(function (error) { deferred.reject(); }); return deferred.promise; };

S

Show previous answers

Intellect App Academy | 04 Feb

Basically in angular js dom manipulation is perform in controllers. But in angular 2 we should implement the DOM manipulation using structural directives. Structural directives are used to remove and add dom elements. This is perform in template or in separate html file. And then we provide link URL to component.

Nikunj Patel | 12 Feb

DOM manipulation should be in a directive instead of the controller. I would define a focus input directive and use it on the button.

G

How to create sliding tabs in ionic ?

0 3

Show previous answers

Lync School | 06 Feb

By using ion-slide-box directive we can resolve your requirement.

Rohit Kumar Srivastava | 12 Feb

Check ion-slide-box tab in ionic framework site.

Thousands of experts Tutors, Trainers & other Professionals are available to answer your questions

Ask a Pro

Recommended for you

Have a Question?

Thousands of expert tutors are available to answer your question

Looking for Angular.JS Training?

Find best Angular.JS Training in your locality on UrbanPro.

FIND NOW

Do you offer Angular.JS Training?

Create Free Profile Now »

Top Contributors

John

7 Answers

Quickitdotnet

5 Answers

Rabbit Templates

4 Answers

Intellect App Academy

4 Answers

Siddharth

4 Answers

Sunil Kumar

3 Answers

Rohit

2 Answers

M Aravind

2 Answers

Bound Tech Solutions

2 Answers

Sponsored

About UrbanPro

UrbanPro.com helps you to connect with the best Angular.JS Training in India. Post Your Requirement today and get connected.

Find Best Angular.JS Training?

Find Now »