angular-services

AngularJS : Pass data from one view to another with in same controller

自闭症网瘾萝莉.ら 提交于 2019-11-28 10:24:12
问题 Summary : I have a form in view( first ) of my angular application and on success response from the ajax call on submit it redirects the user to the view( second ). There is only one controller for the application( for all view ). Here, user can enter the fields in the form from the view( first ) which should get displayed on the view( second ) & again there is a form in the view( second ) where user can enter the fields in the form which should get displayed on the view( third ). As all the

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

时光怂恿深爱的人放手 提交于 2019-11-28 09:39:33
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. 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 module's providers: NgModule({ providers: [DatePipe] }) export class AppModule { } or component's providers:

IONIC 3 CORS ISSUE

痞子三分冷 提交于 2019-11-28 09:13:49
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", "integrations": { "cordova": {} }, "proxies": [ { "path":"/games", "proxyUrl": "https://api-2445582011268

How to send data from one component to another using a shared service [duplicate]

梦想与她 提交于 2019-11-28 08:39:53
问题 This question already has answers here : How to share service between two modules - @NgModule in angular not between to components? (6 answers) Angular - shared service between components doesn't work (2 answers) Closed 2 years ago . I wanted to send data using subject to another component (for a earning purpose). I am not able to fetch back the data. Here is my code: app.component.ts import { Component } from '@angular/core'; import { shareService } from './share.service'; @Component({

Angular 4+ ngOnDestroy() in service - destroy observable

半世苍凉 提交于 2019-11-28 06:08:51
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. Estus Flask OnDestroy lifecycle hook is available in providers. According to the docs: Lifecycle hook that is called when a directive, pipe or service is destroyed. Here's an example :

Passing current scope to an AngularJS Service

﹥>﹥吖頭↗ 提交于 2019-11-28 03:37:30
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? To let the controller know when something async happens, use Angular promises . To provoke the $apply , you don't need the scope, you can call $rootScope.$apply , as there is no difference calling it in a specific scope

Correct way Provide DomSanitizer to Component with Angular 2 RC6

大兔子大兔子 提交于 2019-11-27 14:56:40
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 = 'an-id-goes-here'; let url = `https://www.youtube.com/embed/${id}`; this.videoUrl = this.sanitizer

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

狂风中的少年 提交于 2019-11-27 08:55:21
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/afdelingen.json'; constructor(private http: Http) { } getAfdelingen(): Observable<Afdelingen[]> { return

getting and setting value in factory in angualrjs

空扰寡人 提交于 2019-11-27 08:40:46
问题 This is my factory: .factory('userService',()){ var user = {}; return { getFirstname : function () { return user.firstname; }, setFirstname : function (firstname) { user.firstname = firstname; } } And I'm using this service in my two controllers MainCtrl and AccountEditCtrl I'm using my getFirstname() in my MainCtrl and setFirstname in AccountEditCtrl .controller('MainCtrl',['userService', function(userService){ $scope.userName = userService.getFirstName(); }]); .controller('AccountEditCtrl',

difference between setTimeout in javascript and $timeout service in angularjs

泪湿孤枕 提交于 2019-11-27 08:16:13
Iam new to angular framework.Here is my scenario where, I want to change my $scope.variable after a period of time so i used javascript setTimeout method. $scope.variable = 'Previous'; setTimeout(function(){ $scope.variable='NEXT'; },3000); This code doesn't work for me. I used $apply() to make this code work. Later I came to know that angular itself has a $timeout service which does the same work. $scope.variable = 'Previous'; $timeout(function () { $scope.variable = 'NEXT'; }, 2000); How can i compare performance of $timeout service with javascript setTimeout ?? Why we should use $timeout