angular-services

How to call sibling component method in angular 4?

谁说胖子不能爱 提交于 2019-12-10 11:41:29
问题 I have a header component which is having autocomplete search, when the user search something and select one item from the suggestions dropdown, the body will change accordingly. In body 3 sections are there which is showing based on three different conditions. Here header and body are 2 different components, Hence how to trigger the function in body which is having some logic along with false and true variables. when the user select something from the autocomplete search dropdown. I am

Pattern for returning data from Angular AJAX calls

邮差的信 提交于 2019-12-08 18:11:22
Take a look at this method returned in a factory: fetchEmployeeList: function() { var q = $q.defer(); $http.get('/Employee/') .success(q.resolve) .error(ajaxErrorHandler.handleError); return q.promise; } The author of this code says that this is the model we should use for returning data from HTTP endpoints. Basically, any time we need data from a service, we should use this pattern. The author is under the impression that this is preferred over returning $http.get()'s return value instead. I don't understand the point of this code, though. I thought $http.get() does return a promise. Can

Data will disappear after page refresh,

懵懂的女人 提交于 2019-12-08 13:26:12
问题 Now I am using a service to pass data from view to other view(different controller too), in the view A, I have controller CtrA,for the service I use to pass data is: .factory( 'editreportservices', [ '$q', 'sessionId', function($q, sessionId) { var sharedata = {}; var org={}; function passed(data){ sharedata = data; }; function getsharedata(){ return sharedata; }; function passedorg(data) { org=data; } function getorg() { return org; } return{ passed:passed, getsharedata:getsharedata,

AngularJS: Understanding this PUT example

泪湿孤枕 提交于 2019-12-08 12:50:22
问题 This is the example at : http://docs.angularjs.org/api/ngResource/service/$resource all the way at the bottom. // First get a note object from the factory var note = Notes.get({ id:$routeParams.id }); $id = note.id; // Now call update passing in the ID first then the object you are updating Notes.update({ id:$id }, note); I'm not too sure what this part is doing though. Currently i use get like so: MyService.get(function(data){//do stuff with data}); and after making my updates I'd like to

Angular 6 service injection exception

非 Y 不嫁゛ 提交于 2019-12-08 08:16:32
问题 I started angular two days ago, i m trying to create a service that will do a get request over my spring boot rest end point and I wish to display the result in my angular app Here is what i have tried till now My Service: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { ITweet } from './itweet'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class ReactiveTwitterService { constructor(private http_client:

Pattern for returning data from Angular AJAX calls

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 03:15:07
问题 Take a look at this method returned in a factory: fetchEmployeeList: function() { var q = $q.defer(); $http.get('/Employee/') .success(q.resolve) .error(ajaxErrorHandler.handleError); return q.promise; } The author of this code says that this is the model we should use for returning data from HTTP endpoints. Basically, any time we need data from a service, we should use this pattern. The author is under the impression that this is preferred over returning $http.get()'s return value instead. I

Angular 2 Promise throw error

做~自己de王妃 提交于 2019-12-07 07:51:35
问题 I am trying to make a service that handles contacts in Angular 2. This is what i got so far. import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/toPromise'; @Injectable() export class ContactsService { constructor(private http: Http) { } addContact(contact): Promise<any> { return this.http .post('http://localhost:8000/contacts', contact) .toPromise() .then(response => response.json()) .catch(error => error.json()); } } Now the service

How to call sibling component method in angular 4?

蹲街弑〆低调 提交于 2019-12-07 06:53:28
I have a header component which is having autocomplete search, when the user search something and select one item from the suggestions dropdown, the body will change accordingly. In body 3 sections are there which is showing based on three different conditions. Here header and body are 2 different components, Hence how to trigger the function in body which is having some logic along with false and true variables. when the user select something from the autocomplete search dropdown. I am trying in a communication through service approach. Header code <div class="docs-example-viewer-body custom

How to dynamically create component instance with input/output from a service and inject it to DOM separately?

若如初见. 提交于 2019-12-07 05:13:31
问题 In creating dynamic components in Angular 2, I found out that this process requires ViewContainerRef in order to add newly created component to DOM. And in passing @Input and @Output to those dynamically created components, I found the answer in the second link above and here. However, if I were to create a service named shape.service that contains functions returning different shape components with some @Input like bgColor , I don't know how this service will create a component without

Cannot resolve parameters for ApplicationModule: (?)

喜欢而已 提交于 2019-12-07 04:53:25
问题 Pretty new to Angular. My app contains 1 service and 3 components. Compiled successfully. I'm getting this error and have no idea what went wrong: Uncaught Error: Can't resolve all parameters for ApplicationModule: (?). Debugging gave me very little idea.. It seems that the issue is related to NSLocaleLocalizations having null dependencies (if that makes sense) - see screenshot below: Here is some code: Please let me know if anything else is needed. Your help is much appreciated - thank you