angular-services

get headers from get Http request in Angular

心不动则不痛 提交于 2019-11-27 08:07:54
问题 I'm making a call to an API that gets blob data. back end sends to me also file name in header. My actual problem is that I can't get header from the api. Here's my service.ts public openFile(path) { let url='/download/'; let pathFile= new HttpParams().set('pathFile', path); return this.httpClient.get(url,{params:pathFile, responseType: 'blob' }); and in component.ts I call the service. when I try to print the res.headers I get undefined in console. openFile(path){ this.creditPoliciesService

What is the difference between the $parse, $interpolate and $compile services?

安稳与你 提交于 2019-11-27 05:45:53
What is the difference between $parse , $interpolate and $compile services? For me they all do the same thing: take template and compile it to template-function. pkozlowski.opensource Those are all examples of services that aid in AngularJS view rendering (although $parse and $interpolate could be used outside of this domain). To illustrate what is the role of each service let's take example of this piece of HTML: var imgHtml = '<img ng-src="/path/{{name}}.{{extension}}">' and values on the scope: $scope.name = 'image'; $scope.extension = 'jpg'; Given this markup here is what each service

Passing current scope to an AngularJS Service

南笙酒味 提交于 2019-11-27 05:11:37
问题 Is it correct to pass the "current" $scope to an AngularJS service? I'm in the situation where I've a $service knowing it's consumed by only one controller, and I'd like to have a reference to the controller's scope in the $service methods themselves. Is this philosophically correct? Or I'd better to broadcast events to the $rootScope and then make my controller listen to them? 回答1: To let the controller know when something async happens, use Angular promises. To provoke the $apply , you don

IONIC 3 CORS ISSUE

 ̄綄美尐妖づ 提交于 2019-11-27 03:19:20
问题 I am having a CORS issue with Ionic 3 when attempting to make GET calls to an API. I am using Ionic local server, running ionic serve in the command line for live server. Error No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. I tried updating ionic.config.json with proxy setting but that does not seem to be working.. { "name": "projectLeagueApp", "app_id": "47182aef", "type": "ionic-angular",

How to use angular2 built-in date pipe in services and directives script files [duplicate]

柔情痞子 提交于 2019-11-27 03:03:12
问题 This question already has an answer here: How to use a pipe in a component in Angular 2? 3 answers I need to use angular2's date pipe in services and directives script files(not only in HTML). Does anyone have ideas? Can't upload code cos some policy restrictions, sorry about that. 回答1: Since CommonModule does not export it as a provider you'll have to do it yourself. This is not very complicated. 1) Import DatePipe: import { DatePipe } from '@angular/common'; 2) Include DatePipe in your

@HostBinding and @HostListener: what do they do and what are they for?

强颜欢笑 提交于 2019-11-27 02:41:30
In my meanderings around the world wide interweb, and now especially the angular.io style docs , I find many references to @HostBinding and @HostListener . It seems they are quite fundamental, but unfortunately the documentation for them at the moment is a little sketchy. Can anyone please explain what they are, how they work and give an example of their usage? micronyks Have you checked these official docs? HostListener - Declares a host listener.Angular will invoke the decorated method when the host element emits the specified event. # HostListener - will listen to the event emitted by host

Angular 4+ ngOnDestroy() in service - destroy observable

老子叫甜甜 提交于 2019-11-26 19:33:21
问题 In an angular application we have ngOnDestroy() lifecycle hook for a component / directive and we use this hook to unsubscribe the observables. I want to clear / destory observable that are created in an @injectable() service. I saw some posts saying that ngOnDestroy() can be used in a service as well. But, is it a good practice and only way to do so and When will it get called ? someone please clarify. 回答1: OnDestroy lifecycle hook is available in providers. According to the docs: Lifecycle

Correct way Provide DomSanitizer to Component with Angular 2 RC6

冷暖自知 提交于 2019-11-26 16:49:01
问题 I'm attempting to use DomSanitizer to sanitize a dynamic URL within a Component using I can't seem to figure out what the correct way to specify a Provider for this service is. I'm using Angular 2.0.0-rc.6 Here's my current component: @Component({ templateUrl: './app.component.html', styleUrls: [ './app.component.css' ], providers: [ DomSanitizer ], }) export class AppComponent implements OnInit { public url: SafeResourceUrl; constructor(private sanitizer: DomSanitizer) {} ngOnInit() { let id

Angular: &#39;Cannot find a differ supporting object &#39;[object Object]&#39; of type &#39;object&#39;. NgFor only supports binding to Iterables such as Arrays&#39;

落花浮王杯 提交于 2019-11-26 14:22:42
问题 I've created an angular app which gets data from a json file. But I'm having issues with showing the data in html. A lot of variables are in dutch, I'm sorry for that. I'm also a bit new to all of this :) This is my service: import {Injectable} from '@angular/core'; import {Http, RequestOptions, Response, Headers} from '@angular/http'; import {Observable} from "rxjs"; import {Afdelingen} from "./models"; @Injectable() export class AfdelingService { private afdelingenUrl = '/assets/backend

AngularJS - UI Router - programmatically add states

时间秒杀一切 提交于 2019-11-26 14:20:39
Is there a way to programmatically add states to $stateProvider after module configuration, in e.g. service ? To add more context to this question, I have a situation where I can go with two approaches: try to force the reload on the state defined in the module configuration, the problem is that state has a reloadOnSearch set to false , so when I try $state.go('state.name', {new:param}, {reload:true}); nothing happens, any ideas ? State definition .state('index.resource.view', { url: "/:resourceName/view?pageNumber&pageSize&orderBy&search", templateUrl: "/resourceAdministration/views/view.html