I have two shared modules Core and MasterData.
I am facing issue to use MasterData module's components in my applcation though i can use Core Module's Components. Following is my code.
Core Module (core.module.ts)
import { NgModule, ModuleWithProviders, ComponentFactoryResolver } from '#angular/core';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { FormsModule } from '#angular/forms';
import { HttpModule } from '#angular/http';
import {
IgHierarchicalGridComponent,
IgPivotGridComponent,
IgGridComponent
} from 'igniteui-angular2';
import { CacheModule } from 'angular2-cache';
import { AUTH_PROVIDERS } from 'angular2-jwt';
import { CoreComponents, EntryCoreComponents } from './components';
import { CoreService } from './services';
import { ClientInfoServiceProvider } from './client-info';
import { AuthGuard } from './guards/auth.guard';
const IgniteuiComponents = [
IgHierarchicalGridComponent,
IgPivotGridComponent,
IgGridComponent
];
#NgModule({
declarations: [
...CoreComponents,
...IgniteuiComponents
],
providers: [
...CoreService,
AUTH_PROVIDERS,
AuthGuard,
ClientInfoServiceProvider
],
imports: [
CommonModule,
FormsModule,
RouterModule,
HttpModule,
CacheModule,
],
entryComponents: [
...EntryCoreComponents
],
exports: [
HttpModule,
CacheModule,
RouterModule,
FormsModule,
...CoreComponents,
...IgniteuiComponents
]
})
export class CoreModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: QmsCoreModule,
providers: [
...CoreService,
AUTH_PROVIDERS,
AuthGuard,
ClientInfoServiceProvider
]
};
}
}
Master Data Module (which is inheriting Core because I use infragistics library in core and masterdata components) (masterdata.module.ts)
import { NgModule, ModuleWithProviders, ComponentFactoryResolver } from '#angular/core';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { FormsModule } from '#angular/forms';
import { HttpModule } from '#angular/http';
import { QmsCoreModule } from 'qms/core/qms-core.module';
import { MasterdataComponents } from './components';
import { MasterdataServices } from './services';
#NgModule({
imports: [
CommonModule,
FormsModule,
RouterModule,
HttpModule,
QmsCoreModule.forRoot()
],
declarations: [
...MasterdataComponents
],
providers: [
...MasterdataServices
],
exports: [
FormsModule,
RouterModule,
HttpModule,
QmsCoreModule,
...MasterdataComponents
]
})
export class QmsMasterdataModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: QmsMasterdataModule,
providers: [
...MasterdataServices
]
};
}
}
Master data Module has currently only one component name TeamGrid. (Component Selector is ‘team-grid’)
Main Application AppModule (app.module.ts)
import { BrowserModule } from '#angular/platform-browser';
import { NgModule, Provider } from '#angular/core';
import { QmsMasterdataModule } from 'qms/masterdata/qms-masterdata.module';
import { SwacProxyInterface } from 'qms/core/swac';
import { AppRoutingModule } from './app-routing.module';
import { HomeModule } from './home/home.module';
import { ProjectModule } from './project/project.module';
import { AppComponent } from './app.component';
import { SharedServices } from './shared/services';
export const AppModule = (proxyInterface: SwacProxyInterface, provider: Provider[]) => {
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HomeModule,
ProjectModule,
QmsMasterdataModule.forRoot()
],
providers: [
SharedServices,
...provider
],
bootstrap: [AppComponent]
})
class AppModule {
}
return AppModule;
};
Error message is:
'team-grid' is not a known element:
1. If 'team-grid' is an Angular component, then verify that it is part of this module.
2. If 'team-grid' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '#NgModule.schemas' of this component to suppress this message.
("
[ERROR ->]<team-grid></team-grid>
Can someone help me to find the correct solution for this?
Above Implementation is correct but only mistake is that each modules (Home.module / Project.module) under App.module should also import masterdata.module or core.module as per required compoenents.
This might help you to find out root cause
shared.module.ts
import { NgModule } from '#angular/core';
import { FormsModule } from '#angular/forms';
import { ReactiveFormsModule } from '#angular/forms';
import { HttpModule } from '#angular/http';
import { QmsMasterdataModule } from 'qms/masterdata/qms-masterdata.module';
#NgModule({
declarations: [
],
imports: [
CoreModule,
QmsMasterdataModule
],
exports: [
CoreModule,
QmsMasterdataModule
]
})
export class SharedModule {
}
App Module
import {SharedModule} from './modules/shared/shared.module';
export const AppModule = (proxyInterface: SwacProxyInterface, provider: Provider[]) => {
#NgModule({
declarations: [
AppComponent
],
imports: [
SharedModule
],
providers: [
],
bootstrap: [AppComponent]
})
class AppModule {
}
return AppModule;
};
Related
iam add new ng generate component user-item
this code user-item.component.ts
We started to use the AngularJS in the project but when run serve dont show result in page .whats problem
import { Component, OnInit } from '#angular/core';
import { FormsModule } from '#angular/forms';
#Component({
selector: 'app-user-item',
templateUrl: 'user-item.component.html',
styleUrls: ['user-item.component.css']
})
export class UserItemComponent implements OnInit {
name: string;
constructor() {
this.name = 'test';
}
ngOnInit() {
}
}
user-item.component.html
<p>
user-item works!
</p>
this code app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { NgModule } from '#angular/core';
import { FormsModule } from '#angular/forms';
import { AppComponent } from './app.component';
import { UserItemComponent } from './user-item/user-item.component';
import { UserListComponent } from './user-list/user-list.component';
#NgModule({
declarations: [
AppComponent,
UserItemComponent,
UserListComponent,
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent, UserItemComponent]
})
export class AppModule { }
index.html
<body>
<app-user-item></app-user-item>
--
<app-user-list></app-user-list>
--
<!--<app-root></app-root>-->
-----
</body>
I'm trying to run an ionic app and i'm getting the following:
EDIT: rm -rf Node_Modules got rid of the first error:
I have a home page, another page called flashing, and a texting page. Nothing looks "off" about this code to me.
My code for app.module.ts:
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '#ionic-native/splash-screen';
import { StatusBar } from '#ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import {TextingPage} from '../pages/texting/texting';
import { SMS } from '#ionic-native/sms';
import { HttpModule } from '#angular/http';
import {FlashingPage} from '../pages/flashing/flashing';
#NgModule({
declarations: [
MyApp,
HomePage,
TextingPage,
FlashingPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TextingPage,
FlashingPage,
IonicModule.forRoot(MyApp)
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
]
})
export class AppModule {}
I have an Angular 2 project with components that we bring on build into another project written in angular 1. The problem is the files are like 3rd party, we don't want any one to commit them only use them. The files are enter the "target" folder, but in App.Module.ts I can't set import to that folder. Any idea how to do that correctly?
What I don't understnad is how we can use componenet that written somewhere else if we must declare it in 'app.module.ts' files in order to use it in the project.
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { UpgradeModule } from '#angular/upgrade/static';
import { FormsModule } from '#angular/forms';
import { HttpModule } from '#angular/http';
/* HelloWorldComponent is a 3th party, its files are inside target folder,
so how to import it? */
/* import { HelloWorldComponent } from './app/hello-world.component';*/
#NgModule({
declarations: [
HelloWorldComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
UpgradeModule
],
exports: [
HelloWorldComponent
],
entryComponents: [
HelloWorldComponent
],
bootstrap: []
})
export class AppModule {
ngDoBootstrap() {}
}
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['myApp']);
;})
import * as _angular_ from 'angular';
declare global {
const angular: typeof _angular_;
}
import { downgradeComponent } from '#angular/upgrade/static';
angular.module('myApp')
.directive(
'helloWorld',
downgradeComponent({component: HelloWorldComponent}) as angular.IDirectiveFactory
);
app.routing.ts
import { Routes, RouterModule } from '#angular/router';
import { LoginComponent } from './components/login/login.component';
import { TestsComponent } from './components/tests/tests.component';
import { NotFoundComponent } from './components/notfound/notfound.component';
import { AppModule } from './app.module';
const appRoutes: Routes = [
{ path: 'anmelden', component: LoginComponent },
{ path: 'tests', component: TestsComponent },
{ path: '**', component: NotFoundComponent }
];
export const appRoutingProviders: any[] = [
];
export const routing: AppModule = RouterModule.forRoot(appRoutes);
app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { routing,
appRoutingProviders } from './app.routing';
import { AppComponent } from './components/app/app.component';
import { LoginComponent } from './components/login/login.component';
import { TestsComponent } from './components/tests/tests.component';
import { NotFoundComponent } from './components/notfound/notfound.component';
#NgModule({
declarations: [ AppComponent, LoginComponent, TestsComponent, NotFoundComponent ],
imports: [ BrowserModule, routing ],
providers: [ appRoutingProviders ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
The result:
Edit:
This errors only occurs when using npm start. If I delete the imports: row in the module run npm start and add this line again everything works fine.
I have my root module which looks like this:
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { routing, appRoutingProviders } from './app.routing';
import { LoginModule } from './login/login.module';
import { UserModule } from './user/user.module';
import { NavbarModule } from './navbar/navbar.module';
import { AppComponent } from './app.component';
#NgModule({
imports: [ BrowserModule, routing, NavbarModule ],
declarations: [ AppComponent ],
providers: [ appRoutingProviders ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
I am writing a navbar with various components that handle various parts of the navbar (Im just trying to be really granular, sort of like spotify's approach).
So in the end I will have lots of components that all add up to once navbar, so that felt like a pretty natural use of a module? So I created a navbar module:
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { NavbarComponent } from './navbar.component';
#NgModule({
imports: [ ],
declarations: [ NavbarComponent ],
providers: [ ],
bootstrap: [ NavbarComponent ]
})
export class NavbarModule { }
for the sake of the example ill stick to one navbar component which looks like this
import { Component } from '#angular/core';
#Component({
selector: 'navbar',
templateUrl: './navbar.template.html'
})
export class NavbarComponent { }
the html template just contains standard bootstrap navbar code...
So as you can see I have imported the NavbarModule into the AppModule, which from my understanding of how modules work, should make the NavbarComponent available to all the components I define in the AppModule?
So when I use
in my html template for AppComponent it should render out the NavbarComponent stuff? Instead it just keeps an empty navbar tag?
Any ideas? Also if my understanding of how modules and their imports works is totally off, please could you link some material that could clarify this for me? I have read the angular docs and this is where I got my current understanding from.
Thanks
I found my problem. In the metadata of my navbar module, I was not exporting the navbar component, therefore it was not available to modules that imported it! Solution below
navbar.module
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { NavbarComponent } from './navbar.component';
#NgModule({
imports: [ ],
declarations: [ NavbarComponent ],
providers: [ ],
exports: [ NavbarComponent ],
bootstrap: [ NavbarComponent ]
})
export class NavbarModule { }