Questions tagged [angular-factory]
76 questions
13
votes
4 answers
Angular: Metadata collected contains an error that will be reported at runtime: Lambda not supported
In my Angular app, I'm trying to use a factory provider in my module:
export function getMyFactory(): () => Window {
return () => window;
}
@NgModule({
providers: [
{ provide: WindowRef, useFactory: getMyFactory() },
],
})
export class…

Francesco Borzi
- 56,083
- 47
- 179
- 252
8
votes
3 answers
What is a factory in Angular
I was reading an article of Max NgWizard K, about how Angular updates the DOM. I came across the following:
For each component that is used in the application Angular compiler generates a factory. When Angular creates a component from a factory…

Willem van der Veen
- 33,665
- 16
- 190
- 155
5
votes
1 answer
Angular - useFactory - Error function calls are not supported. Consider replacing the function or lambda with a reference to an exported function
I use Angular AOT compiler version 4.1.3
I have a component library that exports a factory method that is then used to provide a service:
export function libServiceFactory(itemId: string) {
return (http: Http): LibService => {
return new…

nest
- 1,385
- 1
- 15
- 34
4
votes
1 answer
Angular - Dynamic Component Rendering Wrong Data
Solved
As mentioned below by Aaron, the "Other Option" approach works without issues and feels a lot cleaner. I'll leave the updates and everything in case anyone in the future has a similar problem and the workarounds provide useful somehow.
I'm…

iEquivalent
- 73
- 5
3
votes
1 answer
angular factory. how to create new instances of the factory?
I am trying to create new instances of a factory but, all the time it prints the last instance (because of its singleton).
How can I achieve new instance every time I create with the new keyword?
I created example of what I am trying to achieve in…

Alex Koretzki
- 155
- 2
- 11
2
votes
1 answer
Inject query parameter into dependency provider factory in Angular
I want a value from the window.location search parameters passed to the body of a dependency provider factory, ideally in an idiomatic Angular way.
Use case: writing my first Angular app I have the app running on one port and the backend server on…

MvG
- 57,380
- 22
- 148
- 276
2
votes
0 answers
How to access data while using Factory provider in angular4?
when i have a provider like this
{ provide: SaModelService, useValue: 'foo@yahoo.com' }
i am able to get the value by just using like this in the component
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls:…

Lijin Durairaj
- 3,341
- 11
- 31
- 50
2
votes
1 answer
Angular creating named instances of providers
In Angular I have a service to access a cache. The service roughly works like this (but with a lot more asynchronous behavior).
@Injectable()
export class Cache {
cache : CacheTable;
constructor(
protected name : string
) {
…

Raven
- 1,453
- 3
- 18
- 29
2
votes
1 answer
Is it ok to write multiple Angular component in a single file?
I am about to write a common Angular module which can be used as a plug and play module in my application.
What I want
I want to put the module definition and all its factory, directive, constants in a single js file,…

Arpit Kumar
- 2,179
- 5
- 28
- 53
2
votes
1 answer
Angular 2 - good practice during conversion response into angular model
What is a good practice for conversion response (for e.g. json data) into angular model ? So, in other words how to achieve Auto Mapper functionality in angular 2.
team.service.ts
import { Injectable } from '@angular/core';
import { Http, Response }…

wolfpack
- 61
- 3
1
vote
1 answer
How to return $http.post() object with factory function?
When I tried to return a $http.post() object from a factory function with Angular, it throws me this error:
Below is my code:
AngularUtils.js
Fenrir.factory('AngularUtils', function ($http, $log, $window) {
var AngularUtils = {
save:…

TheVicShow
- 83
- 6
1
vote
1 answer
Angular Dynamic Html Template component with event emitter
I am trying to extend the functionality of this component by adding a generic event emitter
import {
Component,
Directive,
NgModule,
Input,
ViewContainerRef,
Compiler,
ComponentFactory,
ModuleWithComponentFactories,
ComponentRef,
…

smclaughlin
- 11
- 3
1
vote
1 answer
using angular factory with $http
I need translate value factory. this factory receive translateData from server. and angular controller call convertValue function. but $http is async method so controller get undefined value. because http response not yet received.
I wonder that I…

hwyoo
- 11
- 3
1
vote
0 answers
Angular 5: Component Factory Binding
I'm using a component factory to load in different components via a Block input which states characteristics of the block - internal variables. Then, depending on the variables set, the factory will load in different components.
Here's my code for…

Johnathan Brown
- 713
- 12
- 35
1
vote
4 answers
Share Variable between controllers of different routes - AngularJS
I'm new on Angularjs and I'm trying to build my first application. Let's say I have to routes that loads two different views:
127.0.0.1:8080/site
127.0.0.1:8080/site_details
Maybe having two different routes is not the right procedure but that it…

Thomas
- 99
- 12