angular-services

Angular: Giving a component field a reference to a service function and calling it from template not working as expected

丶灬走出姿态 提交于 2020-01-11 07:29:28
问题 In my Plunker here (modified Tour of Heroes app from official docs) I created this method in the hero.service doHeroesExist(): boolean { console.log("doHeroesExist called..", this.heroesExist); alert("doHeroesExist called.." + JSON.stringify(this.heroesExist)); return this.heroesExist; } and use it in the app.component class ngOnInit(): void { //this.getHeroes(); this.heroesExist = this.heroService.doHeroesExist; console.log("app ngOnInit called...", this.heroesExist); } as call the

AngularJS - cannot create property method on string

梦想的初衷 提交于 2020-01-06 03:22:10
问题 I am sending a normal get request as follows which was working normally: service.show = function (slug) { console.log(slug) return $http.get('api/packages/'+slug, slug).success(function(response){ service.package = response.package; }); }; Suddenly after I started combining all js files together using gulp I get this weird error: angular.js:10147 TypeError: Cannot create property 'method' on string 'package-38' Since the application is an api so I tried to run the request using postman to see

Unit testing with private service injected using jasmine angular2

巧了我就是萌 提交于 2020-01-02 02:21:26
问题 I have a problem trying to unit test an angular service. I want to verify that this service is properly calling another service that is injected into it. Lets say I have this ServiceToTest that injects ServiceInjected: ServiceToTest .service.ts @Injectable() export class ServiceToTest { constructor(private _si: ServiceInjected) {} public init() { this._si.configure(); } } ServiceInjected.service.ts @Injectable() export class ServiceInjected { constructor() {} public configure() { /*Some

Passing data from one route view to another

别等时光非礼了梦想. 提交于 2019-12-31 04:09:06
问题 I want to pass some values from one view to another in Angularjs using ui-Router. I don't want to use $rootScope to save data or create a new services ( as I have many views that pass small bits of data so creating new jsfile for few lines code is not fun). A super-minified example of what I want to do is: Controller of View 1 $scope.goodFood = 10 $scope.badFood = 2 Controller of View 2 $scope.results = 10 - 2 (from view 1's scope) Is there any quick way to do these kinds of small operations

Passing data from service to Component --> Child Components

你说的曾经没有我的故事 提交于 2019-12-31 03:00:52
问题 To be very short i am using this Plunker I have a scenario where i have to create controls dynamically by reading the elements data from a service. So when i read the data from the service its asynchronous.But i have to create some concrete objects based on the data i receive from the service and pass it to the child components. So here is my logic Html for the Main Component is as below. <ion-content padding class="container" *ngIf="questions"> <app-dynamic-form [questions]="questions"></app

Cannot read property 'isXXXXX' of undefined [closed]

≡放荡痞女 提交于 2019-12-25 18:48:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 months ago . I am trying to use a shared service on one of my components. When I am using with app root component then it is working fine. When I am trying to use on another module/dashboard then I am getting an error. shared/authorize.service.ts @Injectable() export class AuthorizationService { isDoingSomething() { return

angular Uncaught ReferenceError: Service is not defined

ε祈祈猫儿з 提交于 2019-12-25 09:15:01
问题 I have the following component in which I am trying to inject a service: angular. module('phoneList'). component('phoneList', { templateUrl: '/static/common/angular/phone-list/phone-list.template.html', controller: ['$http', 'authenticationService', function PhoneListController($http, authenticationService) { var self = this; authenticationService.authenticate().then(function(){ console.log('it worked!!!!!!!!'); }); } ] }); The service looks like this: angular.module('authentication').factory

testing .success and .error of service in controller jasmine

筅森魡賤 提交于 2019-12-25 08:18:51
问题 I have a call to service's function in a controller. Below is the code Service (function () { 'use strict'; angular.module('MyApp') .service('MyService', ['$http', function ($http) { return { getMyData: function (extension) { return $http.get('www.something.com'); } }; }]) })(); Controller var getMyData = function () { MyService.getMyData(extension).success(function (results) { //Some functionality here }) .error(function (err, status) { //Some functionality here }); } $scope.Call=function(){

Angular Service JSONP Request with Custom Callback

梦想与她 提交于 2019-12-25 03:42:05
问题 I'm pulling from JSONP feeds that have custom callback functions, for example: jsonpCallbackAllStar2015({ "events": [ { "title": "XYZ" } ... ] }) I'm able to do this, using the solution posted here like so: var jsonUrl = 'http://i.cdn.turner.com/nba/nba/.element/media/2.0/teamsites/warriors/json/json-as2015.js?callback=JSON_CALLBACK' + (new Date().getTime()); $http.jsonp(jsonUrl); window.jsonpCallbackAllStar2015 = function(data) { $scope.events = data.events; } However I would now like to do

Angular 5 : Authentication guard automatically navigate to specified compnonent

蹲街弑〆低调 提交于 2019-12-25 03:15:18
问题 I have set an authentication guard with firebase email and password login, the issue is that it automatically trigger the route to the specified component I have implemented the authentication guard and set it in the correct module provider (because I have many providers in my application. This is my authentication service: import { Injectable } from '@angular/core'; import { Router, Route ,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, CanLoad } from '@angular