angular-module

“Please add a @NgModule annotation” Error on Angular2

拟墨画扇 提交于 2019-12-03 17:47:24
问题 I have made a custom angular2(5.0.x) module that looks like this : import { GuageService } from './services/guage.service'; import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { GuageComponent } from './guage/guage.component'; @NgModule({ declarations: [GuageComponent], imports: [ CommonModule ], providers : [GuageService], exports : [GuageComponent] }) export class GuageModule {} I use it in my app modules like this: import { BrowserModule } from

What is the calling order of angularjs functions (config/run/controller)? [duplicate]

我的梦境 提交于 2019-11-30 07:35:02
This question already has an answer here: AngularJS app.run() documentation? 2 answers There are controllers constants directives services factory run config filters functions of angular.js . What is the calling order of all these modules? Learning this I made a fiddle observing the behaviour by console.log . Its like app config app run directive setup directive compile (app controller dependencies) service factory inner factory inner service app controller filter directive linking filter render (w.r.t the markup) Observe yourself here (Check Console). EDIT New Fiddle with filters added 来源:

Role of imports / exports in Angular 2+ ngModule

不问归期 提交于 2019-11-29 20:09:13
I'm learning Angular 2+ and I'm having a hard time understanding the role of imports/exports in an ngModule. More specifically why is important to import a module if you're going to import it anyway using es6 syntax as well import { BrowserModule } from '@angular/platform-browser'; @NgModule({ imports: [ BrowserModule ], providers: [ Logger ], declarations: [ AppComponent ], exports: [ AppComponent ] }) Wasn't much simpler to detect that the module was imported via es6 syntax? imports - other modules whose exported classes are needed by component templates declared in this module. But we're

Load ngModule and its components based on conditional in Angular

别来无恙 提交于 2019-11-29 11:53:46
I'm new in angular and I was wondering if it's possible to load and module and its components I made based on a conditional on the app.module or where would it be the best place to do this. Basically I want to do something like: if(user.deparment === 'coms') { //Use the communications.module and its components } I have attached some picture so you guys can see the structure of the app. if necessary I can add the code instead of a picture. App.module picture Communications.module picture You can do a simple ternary check to conditionally import a module. Like this: import { NgModule, Optional }

Directive doesn't work in a sub module

柔情痞子 提交于 2019-11-29 07:32:17
问题 I can't make the directive work in a lazy loaded module. I've read the documentation and I simply added the directive into declarations array of my main module. The directive works as expected at that module, but it doesn't work in lazy loaded modules. It even prevents lazy loaded module to be opened because of the template error: Can't bind to 'myHighlight' since it isn't a known property of 'p' Here's my Plunker. Check out errors in console after clicking 'go to child' 回答1: That's because

Custom RouteReuseStrategy for Angular's child module

故事扮演 提交于 2019-11-29 00:29:45
I want to use this custom route reuse strategy for just one module: export class CustomRouteReuseStrategy extends RouteReuseStrategy { public shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; } public store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {} public shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; } public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null; } public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { return true; } } So I've passed into

Role of imports / exports in Angular 2+ ngModule

血红的双手。 提交于 2019-11-28 15:38:03
问题 I'm learning Angular 2+ and I'm having a hard time understanding the role of imports/exports in an ngModule. More specifically why is important to import a module if you're going to import it anyway using es6 syntax as well import { BrowserModule } from '@angular/platform-browser'; @NgModule({ imports: [ BrowserModule ], providers: [ Logger ], declarations: [ AppComponent ], exports: [ AppComponent ] }) Wasn't much simpler to detect that the module was imported via es6 syntax? imports - other

Angular - Module Separation - Best Practice for shared or common code

那年仲夏 提交于 2019-11-28 10:00:17
问题 I have some Angular services that have identical methods for parsing the json response, handling errors etc (eg. trapping if it's a 422 error for example). Obviously I don't want these methods copy and pasted into each service, but I cannot seem to find any guidance on where I should put this code. They are not class methods, just currently identical private methods in each service. Here's one for example: private parseToString(jsonResponse: any){ return Object.keys(jsonResponse).reduce(

Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?

痞子三分冷 提交于 2019-11-28 07:01:59
In Angular 5, if I had AbstractClassService and ExtendedClassService that extends the abstract, I could do this in my NgModule's providers array: @NgModule({ providers: [ {provide: AbstractClassService, useClass: ExtendedClassService} ] }) export class AppModule {} This would allow me to switch ExtendedClassService with another for testing or whatever very easily. This can still be done with Angular 6, however there is the new providedIn option that can be set within the service itself to reduce bundle size: @Injectable({providedIn: 'root'}) export class ExtendedClassService extends

Angular 2 'component' is not a known element

五迷三道 提交于 2019-11-27 17:33:58
I'm trying to use a component I created inside the AppModule in other modules. I get the following error though: "Uncaught (in promise): Error: Template parse errors: 'contacts-box' is not a known element: If 'contacts-box' is an Angular component, then verify that it is part of this module. If 'contacts-box' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. My project structure is quite simple: I keep my pages in pages directory, where each page is kept in different module (e.g. customers-module) and each module has