Angular 2 Stuck on Loading AppComponent content here - angularjs

I have been following along to this tutorial on youtube to learn Angular 2. Just after the 33:00 mark, where I import the headerComponent into the app.module.ts, localhost begins perpetually displaying "Loading AppComponent content here". Meanwhile, in the video, the header and content load almost immediately. What am I doing wrong? Here is my code:
app.component.ts:
import { Component } from '#angular/core';
import { headerComponent } from './header/app.headerComponent';
#Component({
selector: 'my-app',
templateUrl: './main.html',
})
export class AppComponent {
}
app.headerComponent.ts:
import { Component } from '#angular/core';
#Component({
selector: 'header',
templateUrl: './header/header.html',
})
export class headerComponent {
}
app.module.ts:
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { AppComponent } from './app.component';
import { headerComponent } from './header/app.headerComponent';
#NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, headerComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }

Credit goes to TK Omble for finding out the issue. There was a build error because I was loading a header template from a folder called header within header folder. Now I changed the templateUrl: './header/header.html' to templateUrl: './header.html' and it works fine.

Related

How to use Angular 2 component in Angular 1 app using #angular/upgrade

This question might be duplicate but I have tried all possible options.
I am trying to use my Angular 2 component in Angular 1 app using #angular/upgrade.
angular2 files :-
simple hello component in app/components/hello.
hello.component.ts
import { Component, OnInit } from '#angular/core';
#Component({
selector: 'app-hello',
templateUrl: './hello.component.html',
styleUrls: ['./hello.component.scss']
})
export class HelloComponent implements OnInit {
constructor() {
}
ngOnInit() {
}
}
hello.component.html
<p>
hello works!
</p>
app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { UpgradeModule } from '#angular/upgrade/static';
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HelloComponent } from './components/hello/hello.component';
#NgModule({
declarations: [
AppComponent,
HelloComponent
],
imports: [
BrowserModule,
UpgradeModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [
HelloComponent
]
})
export class AppModule {
constructor(private upgrade: UpgradeModule) { }
ngDoBootstrap() {
this.upgrade.bootstrap(document.body, ['usr']);
}
}
platformBrowserDynamic().bootstrapModule(AppModule);
In my Angular 1 app :-
app.ts (root file)
import { HelloComponent } from '../angular/src/app/components/hello/hello.component';
import { downgradeComponent } from './node_modules/#angular/upgrade/static/static'
let moduleList = ['ngCookies', 'ngSanitize','$rootScope', '$locationProvider '];
angular.bootstrap(document.body, ['usr']);
let app: any = angular.module('usr', moduleList)
.directive(
'appHello',
downgradeComponent({ component: HelloComponent })
);
index.html of Angular 1 (I have added base href and root which is default component of angular, app-root component is rendering properly in my angular 1 app)
<base href="/">
<app-root></app-root>
header.html (angular 1 header component where I want to show my angular 2 hello component)
<app-hello></app-hello>
screenshots.
Thanks in advance.
https://angular.io/api/upgrade/static/downgradeModule says
You cannot use downgradeModule() and UpgradeModule in the same hybrid
application. Use one or the other.
This means you can only use downgrade module while bootstrapping NG1

Can't resolve all parameters for Auth: (?) error, ionic2 AngularJS

i wanted to provide authonification to my ionic2 app, so i followed the official documentation and applied it to a brand new ionic2 app ionic start my_app blank
once i serve my app, this error fires :
Error: Can't resolve all parameters for Auth: (?).
at syntaxError (http://localhost:8100/build/main.js:107898:34)
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:8100/build/main.js:121235:35)
at CompileMetadataResolver._getTypeMetadata (http://localhost:8100/build/main.js:121103:26)
at CompileMetadataResolver._getInjectableMetadata (http://localhost:8100/build/main.js:121089:21)
at CompileMetadataResolver.getProviderMetadata (http://localhost:8100/build/main.js:121379:40)
at http://localhost:8100/build/main.js:121308:49
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/main.js:121269:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/main.js:120924:50)
at JitCompiler._loadModules (http://localhost:8100/build/main.js:131988:66)
i've injected Auth with providers in app.moodule.ts as you can
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 { Auth } from '#ionic/cloud-angular';
#NgModule({
declarations: [
MyApp,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
],
providers: [
StatusBar,
SplashScreen,
Auth,
{provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule {}
according to my researches, this error comes from:
Having forgot to decorate the Auth class with #Injectable() or #Inject(Auth)
i have tried doing so by injecting :
#IonicPage()
#Component({
selector: 'page-home',
templateUrl: 'home.html',
})
#Injectable()
export class HomePage {........}
OR
export class HomePage {
constructor(#Inject(Auth) public auth: Auth) {
}
.......
}
But this shows the same error though.
Having a dependency in the Auth constructor that i haven't provided in app.module.ts
as you can see, i've handled this case in my code.
A circular dependency.
which i really think is the issue here, honestly i got a clue how to check this out since i still a beginner.
Hope someone can help

Plunker and Angular 2 child components don't display output

I have the most basic angular 2 plunk but no errors are shown to give any indication of a problem. Why can't I see any template output from the child components? Is this a Plunker Issue or is it me?
Plunker version here with Index.html
PARENT: hello_world.ts
import {Component} from 'angular2/core';
import {Jupiter} from './jupiter';
import {Uranus} from './uranus';
#Component({
selector: 'hello-world',
template: `
<p>Can you see jupiter?</p>
<jupiter></jupiter>
<p>Can you see Uranus?</p>
<uranus></uranus>
`
})
export class HelloWorld {
}
CHILD: jupiter.ts
import {Component} from 'angular2/core';
#Component({
selector: 'jupiter',
template: `<p>Hello I'm Jupiter</p>`
})
export class Jupiter {}
CHILD: uranus.ts
import {Component} from 'angular2/core';
#Component({
selector: 'uranus',
template: `<p>Hello I'm Uranus Lol</p>`
})
export class Uranus {}
I've used my demo and used your code to get your expected results that you can see here: https://embed.plnkr.co/VKrvg4/
SystemJS Bootstrap Process
Basically, I've created a main.ts file that is used by SystemJS and then the code in this file bootstraps Angular with the help of AppModule.
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
Declaration
This app module is responsible to declare the components that you would like to register in your Angular application using declarations.
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { AppComponent } from './app.component';
import { HelloWorldComponent } from './hello-world.component'
import { JupiterComponent } from './jupiter.component'
import { UranusComponent } from './uranus.component'
#NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, HelloWorldComponent, JupiterComponent, UranusComponent],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Bootstrap
The same module also uses AppComponent to bootstrap your Angular application in the code above. The component registered here will be rendered as parent component.
Component Rendering Process
When the app component is rendered, its template uses two other components. Now Angular is aware of your other components as it was registered using declarations.
import { Component } from '#angular/core';
#Component({
selector: 'hello-world',
template: `
<p>Can you see jupiter?</p>
<jupiter></jupiter>
<p>Can you see Uranus?</p>
<uranus></uranus>
`
})
export class HelloWorldComponent {
}
You should be able to see your other component UI in view.

How to achieve date filtering in Angular2

I have a class inside of which I want to use date filtering as it used to be in Angular 1:
$filter('date')(startDate, 'yyyy-MM-dd HH:mm:ss')
Now I want to achieve this using Angular 2. As far as I can see, I could use DatePipe class. But the problem is that I don't know how to import it inside of my class file:
import { Injectable } from '#angular/core'
import { Http, Response, Headers } from '#angular/http';
import { InputValidatorService } from './input-validator.service';
import { Pipe, PipeTransform } from '#angular/core';
...
myFunctionInsideOfAClass(){
var datePipe = new DatePipe(); // Symbol 'DatePipe' can not be properly resolved, probably it is located in inaccessible module.
}
How can I achieve this?
EDIT: My app module:
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { FormsModule } from '#angular/forms';
..
#NgModule({
imports: [BrowserModule, FormsModule, HttpModule],
declarations: [AppComponent, MapComponent, AtileLayerDirective, MapDirective, mapControlDirective, ToolsComponent, SearchComponent],
bootstrap: [AppComponent],
providers: [{
provide: Http,
useFactory: (_backend: ConnectionBackend, _defaultOptions: RequestOptions) => new HttpInterceptor(_backend, _defaultOptions),
deps: [XHRBackend, RequestOptions]
}, mapManager, SearchService, StatusIconProvider
]
})
import {DatePipe} from '#angular/common';
#NgModule({
...
providers: [ /* other providers */, DatePipe],
...
})

Angular 2.0 Routing Issue

In my main.ts the code is like this.
import {provide, enableProdMode} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import {APP_BASE_HREF} from 'angular2/platform/common';
import {AppComponent} from './app/components/app.component';
enableProdMode();
bootstrap(AppComponent, [
ROUTER_PROVIDERS, HTTP_PROVIDERS,
provide(APP_BASE_HREF, { useValue: '<%= APP_BASE %>' })
]);
In my app.component.ts file I have the follwing code.
import {Component} from 'angular2/core';
import {enableProdMode} from 'angular2/core';
import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams} from 'angular2/router';
import {SportsLiveFeedService} from '../shared/index';
import {MainComponent} from '../main/index';
import {ResultsComponent} from '../results/index';
#Component({
selector: 'sd-app',
viewProviders: [SportsLiveFeedService],
templateUrl: 'app/components/app.component.html',
styleUrls: ['css/bootstrap.min.css', 'css/main.css'],
directives: [ROUTER_DIRECTIVES]
})
#RouteConfig([
{
path: '/',
name: 'Main',
component: MainComponent
},
{
path: '/results/:id',
name: 'Results',
component: ResultsComponent
}
])
export class AppComponent {
constructor(private router: Router) {}
}
And in the ResultsComponent my code is like this.
import {Component} from 'angular2/core';
import {Inject} from 'angular2/di';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common';
import {SportsLiveFeedService} from '../../shared/index';
#Component({
selector: 'sd-about',
templateUrl: 'app/results/components/results.component.html',
styleUrls: ['css/bootstrap.min.css', 'css/main.css'],
directives: [FORM_DIRECTIVES, CORE_DIRECTIVES],
providers: [SportsLiveFeedService]
})
export class ResultsComponent implements OnInit {
eventsDetails: [];
constructor(private _sportsLiveFeedService: SportsLiveFeedService){
this._sportsLiveFeedService = _sportsLiveFeedService;
}
ngOnInit(){
this._sportsLiveFeedService
.getEachEventInDetailByMeetingId()
.subscribe(p => this.eventsDetails = p)
}
}
The issue is when I first screen is loading just fine. But when I navigate to http://localhost:5555/results/121212 like this, The second screen UI is not showing. Please help me to fix this issue. I am new to Angular 2.0

Resources