angular-services

Angular service doesn't work within other service

送分小仙女□ 提交于 2019-12-11 17:34:27
问题 I'm using ngx-translate library for translations. In my components (lazy loaded routes) When I set the following, it works fine: constructor( public translate:TranslateService ) { this.translate.setDefaultLang( this.langService.lang ); this.translate.use( this.langService.lang ); } I have my own LangService just to save user's selected language. I set it to lang property and use TranslateService there: lang:string = "fa"; constructor(public translate: TranslateService) { // this works console

What is the proper way to share data between two components using rxjs ReplaySubject?

£可爱£侵袭症+ 提交于 2019-12-11 17:08:58
问题 I've developed a component with two views. Component A has a contact form, and Component B is the "Thank you" page. Component A: You fill the form and submit it. As soon as the response arrives, a new ReplaySubject value is created. The user will be routed to the component B. Component B: The component is initialized. The component gets the value from the subject. The view is rendered and displays the thank you message. HTTP Call response (Returned after a successful Form data post request):

Using directive with different services in Angular

三世轮回 提交于 2019-12-11 16:36:33
问题 I must be approaching this from a false perspective, but here is the problem. I have an async validation directive which uses HttpClient to validate something with the backend. It is almost independent apart from one critical thing – it needs correct HTTP headers to pass authentication on the server side. This is how the constructor looks: constructor( private http: HttpClient, private auth: AuthService, @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[] ) {

Cannot read property of undefined in angular karma test

寵の児 提交于 2019-12-11 15:36:27
问题 I am testing a service function which makes numerous $http.get() calls. The actual function under test returns a promise. Currently, the test is failing with response is undefined . Here is the test: it('should return the list of catalogues', inject(function ($q, bookService) { var list; var deferred = $q.defer(); var promise = deferred.promise; promise.then(function (response) { list = response.success; // Cannot read property 'success' of undefined }); bookService.getCatalogues().then

Angular Translate async timing issue with $translateProvider.useStaticFilesLoader

℡╲_俬逩灬. 提交于 2019-12-11 12:02:34
问题 I am using the excellent Angular Translate ( $translate ) directive/service to deal with multiple Locale Languages and since I have multiple locale files I use the convenient $translateProvider.useStaticFilesLoader to load my translation files through a structure of localeAbbr.json, for example en.json , es.json , etc... I built a Plunker to show my open source project and that project uses the locale through Git raw files (pointing to the actual Github repository, meaning not local to the

Angular testing: testing angular Services with private methods

我的未来我决定 提交于 2019-12-11 11:33:20
问题 lets say I got this kind of method on a service: this.search = function (term) { var deferred = $q.defer(); Restangular.all('search').getList(params) .then(_onRestResult.bind(this, deferred)) .catch(_onRestError.bind(this, deferred)); return deferred.promise; } function _onRestResult(deferred, data) { // notice it isn't on the this //doSomthing } But running a basic test. when I change the then clause to an anonymous function, everything works as expected, but when I used the named private

AngularJS Ajax Call in Service

£可爱£侵袭症+ 提交于 2019-12-11 09:53:24
问题 I want my application to make Ajax Calls to a RESTful Webservice. In my html document are two textboxes that are connected to a scope object. Both fields are connected to the "post" function via ng-change. The post method sends the "form" variable from the scope to the API and the webservice adds both numbers and responds with a json file, which now contains the result. (This might not be very RESTful but it works for me) It works perfectly fine as long as I have the Ajax call in my

Angular services : selecting the correct url on click event

时光总嘲笑我的痴心妄想 提交于 2019-12-11 08:43:27
问题 I am trying to figure out or to make my services to get the correct url on event.the case is that I have a template with multiple tab and each one display a set of data on event binding , this is what it looks like : <div class="card-tabs"> <ul materialize="tabs" class="tabs tabs-fixed-width" (click)='select()'> <li class="tab"><a class="active" href="#west (click)='west()'>{{Department[0]}}</a></li> <li class="tab"><a href="#center" (click)='center()'>{{Department[1]}}</a></li> </ul> </div>

Angular 5 StaticInjectorError:[Http]

假装没事ソ 提交于 2019-12-11 06:56:42
问题 hello i am getting such an error what is the reason for this? StaticInjectorError[Http]: StaticInjectorError[Http]: NullInjectorError: No provider for Http! at NullInjector.get (core.js:923) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153)enter code here at StaticInjector.get (core.js:1024) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveNgModuleDep (core.js:10585) at NgModuleRef.get (core.js:11806) at resolveDep

Angular Guard is not able to access the Angular Service Object

浪尽此生 提交于 2019-12-11 06:37:25
问题 I am trying to access the Angular Service Object (I have set the AuthContext in service) but Angular Guard is giving undefined even though that is well set. I have login component, which I call first and internally It uses the Angular Auth Service. In the constructor of that service, I ensure that AuthContext is well set. Through the debug, I have seen that object is available with all the required claims. But then when I access the regular component (which I have guarded through the Auth