angular-services

Error loading @angular/common/http - angular 2

二次信任 提交于 2019-12-11 06:25:12
问题 I am trying to implement a service in Angular 2. Service: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import { BrowserModule } from '@angular/platform-browser'; @Injectable() export class DemoService { constructor(private http: HttpClient ) { } GetData(): Observable<String> { const baseUrl = 'http://localhost:54037/api/home'; // this part will come from config file in futer // const url = '

How can I cache some data in angular 4 service?

回眸只為那壹抹淺笑 提交于 2019-12-11 06:02:38
问题 I have a service that I call to pull some data from my rest service. I have an object that I set inside my service with the result from the rest call. The problem is that when I call the get function to return the object I always get undefined. I currently have the call to my service on the application root onInit function. Any help on how I could load this data and store on the object so next time I need to access it I do not need to make a remote call to my rest service? Here is my service

AngularJS Update Service Variable Not Working

大兔子大兔子 提交于 2019-12-11 04:34:36
问题 I have a list of images. One next to the other. I'm trying to capture which image was clicked, populate a modal div and show it. Markup <section class="portfolio-grid column small-12" ng-controller="PortfolioCtrl"> <ul class="small-block-grid-2 medium-block-grid-4"> <li ng-repeat="portfolio in portfolios"> <a ng-click="showModal($index)" title=""> <img ng-src="{{portfolio.thumb}}" alt=""> <div class="details"> <h4>{{portfolio.name}}</h4> </div> </a> </li> </ul> </section> ======== Some Other

Access parent controller methods from directive?

不问归期 提交于 2019-12-11 03:04:25
问题 I have a question with some page about item search. Let's say I have: A controller with result items to display A service that performs the search queries and interacts to the controller so it updates the result items to display A directive which has the form with all the inputs of the search fields. One of the buttons is a "View more items" button. It should only be shown if the response that I receive from a query tells me that there are more items to view. I made a function inside the

How to get values of reactive form inputs in Angular?

这一生的挚爱 提交于 2019-12-11 00:47:03
问题 I need to grab reactive form inputs email and password and pass them to my function which calls register service method to register new user in firebase using email. Unfortunately, in chrome console after form submission I get RegisterComponent.html:2 ERROR ReferenceError: email is not defined My code looks like this now: register.component.ts export class RegisterComponent { form: FormGroup; constructor(fb: FormBuilder, private authService: AuthService) { this.form = fb.group({ email:[''

Share data between controllers in AngularJS

此生再无相见时 提交于 2019-12-10 22:08:25
问题 I use the following factory to fetch data from API and store it to local variable called apiData. app.factory('MyFactory', function($resource, $q) { var apiData = []; var service = {}; var resource = $resource('http://example.com/api/sampledata/'); service.getApiData=function() { var itemsDefer=$q.defer(); if(apiData.length >0) { itemsDefer.resolve(apiData); } else { resource.query({},function(data) { apiData=data; itemsDefer.resolve(data) }); } return itemsDefer.promise; }; service.add

Getting [object Object] while mapping http response in Angular 2

丶灬走出姿态 提交于 2019-12-10 18:22:24
问题 I am getting an [object Object] while using Observable map in angular 2. Here is the response object from the API service. { "isSuccess": true, "message": "Connection Successfull", "data": [ { "marketId": 1, "city": "san", "cityF": "san", "name": null, "nameF": "hello", "sortOrder": 1, "isActive": true }, { "marketId": 2, "city": "san", "cityF": "san", "name": null, "nameF": "hello", "sortOrder": 1, "isActive": true }, { "marketId": 3, "city": "san", "cityF": "san", "name": null, "nameF":

Angular Hybrid Error: Trying to get the AngularJS injector before it being set

心已入冬 提交于 2019-12-10 17:34:35
问题 How to use AngularJS service in Angular 5 component? I have AngularJS application and i am trying to make hybrid app but not able to use AngularJS service insight Angular component : getting error ERROR Error: Trying to get the AngularJS injector before it being set. my main.ts is import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; platformBrowserDynamic().bootstrapModule(AppModule); app.module : import { BrowserModule } from '

How to call function in ng-click which is defined in factory service

余生长醉 提交于 2019-12-10 16:24:35
问题 How can I call the function in ng-click which is defined inside a factory service, app.factory('MyFactory', [function () { return { setTest: function(test) { alert(test); } }; }]); app.controller('TestCtrl', ['$scope','MyFactory', function ($scope, MyFactory) { }]); <li><a href="#" ng-click="setTest('PHP')">PHP</a></li> <li><a href="#" ng-click="setTest('Javascript')">Javascript</a></li> 回答1: The method should be defined on your scope for it to be usable in bindings. In your controller you

Angular folder structure and component services

故事扮演 提交于 2019-12-10 15:26:07
问题 I have read many articles about Angular folder structure. It is still not clear to me where do we put component services. Shared services between components are put under shared. But what about a service that is used only by a component? Usually I put all my component logic into a service and leave the component with code relevant only to UI stuff. Which one is better to use: Each component and its service into the same folder --app.component.html --app.component.ts --app.module.ts --app