I have an error in console after authentication. After reload page CreateChartComponent page start working. Error just happen in authentication process.
Uncaught (in promise): Error: Cannot find primary outlet to load 'CreateChartComponent'
This is the login function.
login(event, username, password): void {
event.preventDefault();
this.authService.login(username, password).subscribe(
res => {
this.router.navigate(['drawing']);
},
err => {
// todo: handle error with a lable
console.log(err);
if (err.ok === false) {
this.errorMessage = 'Error logging in.';
}
});
}
}
Aditional information:
I send clear mode of code where I get same issue.
It's Router code:
// Import our dependencies
import { Routes } from '#angular/router';
import { AppComponent } from './app.component';
import { LoginComponent } from './home/login/login.component';
import { CreateChartComponent } from './home/drawing/create-chart.component';
import { AuthGuard } from './auth.guard';
// Define which component should be loaded based on the current URL
export const routes: Routes = [
{ path: '', component: CreateChartComponent, pathMatch: 'full', canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'drawing', component: CreateChartComponent, canActivate: [AuthGuard] },
];
and its create-chart.component.ts
import {
Component,
OnInit,
} from '#angular/core';
#Component({
selector: 'np-chart-create',
templateUrl: './create-chart.component.html',
styleUrls: ['./create-chart.component.css']
})
export class CreateChartComponent implements OnInit {
ngOnInit() {
}
}
Related
VERSION: Ionic 4
Plugin: phonegap-nfc
Hi everyone!
I'm trying to use this plugin (https://ionicframework.com/docs/native/nfc) and following the instructions, I should be able to read a message sent from another NFC device. The event is fired and I know something is sent, but I'm not able to understand what and where the message is stored.
This is the code:
home.page.ts
import { Component } from '#angular/core';
import {Ndef, NFC} from '#ionic-native/nfc/ngx';
import {AlertController} from '#ionic/angular';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private nfc: NFC, private ndef: Ndef, private alertController: AlertController) { }
readNFC() {
this.nfc.addNdefListener(() => {
this.presentAlert('ok');
}, (err) => {
this.presentAlert('ko' + err);
}).subscribe((event) => {
console.log(event);
console.log(JSON.stringify(event));
this.presentAlert('Il messaggio contiene' + event.tag + ' ' + this.nfc.bytesToHexString(event.tag.id));
});
}
writeNFC() {
this.nfc.addNdefListener(() => {
console.log('successfully attached ndef listener');
const message = this.ndef.textRecord('Hello world');
this.nfc.share([message]).then(
value => {
this.presentAlert('ok');
}
).catch(
reason => {
this.presentAlert('ko');
}
);
}, (err) => {
this.presentAlert('ko' + err);
});
}
async presentAlert(mess) {
const alert = await this.alertController.create({
header: 'attenzione',
message: mess,
buttons: ['OK']
});
await alert.present();
}
}
app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { RouteReuseStrategy } from '#angular/router';
import { IonicModule, IonicRouteStrategy } from '#ionic/angular';
import { SplashScreen } from '#ionic-native/splash-screen/ngx';
import { StatusBar } from '#ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import {Ndef, NFC} from '#ionic-native/nfc/ngx';
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
NFC,
Ndef
],
bootstrap: [AppComponent]
})
export class AppModule {}
This is the stringify obtained by printing the content of event:
{"isTrusted":false,"tag":{"id":[0],"techTypes":["android.nfc.tech.Ndef"],"type":"android.ndef.unknown","maxSize":0,"isWritable":false,"ndefMessage":[{"tnf":1,"type":[85],"id":[],"payload":[3,112,108,97,121,46,103,111,111,103,108,101,46,99,111,109,47,115,116,111,114,101,47,97,112,112,115,47,100,101,116,97,105,108,115,63,105,100,61,99,111,109,46,119,97,107,100,101,118,46,119,100,110,102,99,38,102,101,97,116,117,114,101,61,98,101,97,109]},{"tnf":4,"type":[97,110,100,114,111,105,100,46,99,111,109,58,112,107,103],"id":[],"payload":[99,111,109,46,119,97,107,100,101,118,46,119,100,110,102,99]}],"canMakeReadOnly":false}}
Thanks in advance for your help!
Your data is at
ndefMessage[0].payload
you need to use
nfc.bytesToString()
the payload to convert to string
When I log into the application, angular changes the ulr to https://baseurl/app/home and the home page renders correctly. If I refresh the page I get a server (500) error. if I remove the /app/home part in the address bar and refresh, the page reloads without issues.
In the logs on the server side I find this:
Fail: Microsoft.AspNetCore.SignalR.HubConnectionContext[5]
Failed connection handshake.
I am running the angular client and the .net core application on two different servers, and CORS is set up correctly and the client app is able to connect to the api. The app works fine except when i refresh a page with an angular route.
The problem does not occur when I run the application locally on my development machine.
I have not changed any routing or signalr related code in the original Abp Zero template.
On server:
.NetCore 2.2
Abp Zero v 4.8
services.AddSignalR() is called in the startup.cs file and
app.UseSignalR(routes =>
{
routes.MapHub("/signalr");
});
is also called in the startup.cs file from the Configuration method. All this is standard tempate code.
In Angular client:
#aspnet/signalr v 1.1.4
The unchanged SignalRAspNetCoreHelper of which the initSignalR() is called in OnInit in the app.component.ts file:
import { AppConsts } from '#shared/AppConsts';
import { UtilsService } from '#abp/utils/utils.service';
export class SignalRAspNetCoreHelper {
static initSignalR(): void {
const encryptedAuthToken = new UtilsService().getCookieValue(AppConsts.authorization.encrptedAuthTokenName);
abp.signalr = {
autoConnect: true,
connect: undefined,
hubs: undefined,
qs: AppConsts.authorization.encrptedAuthTokenName + '=' + encodeURIComponent(encryptedAuthToken),
remoteServiceBaseUrl: AppConsts.remoteServiceBaseUrl,
startConnection: undefined,
url: '/signalr'
};
jQuery.getScript(AppConsts.appBaseUrl + '/assets/abp/abp.signalr-client.js');
}
}
The app-routing.module.ts is also unchanged:
import { NgModule } from '#angular/core';
import { RouterModule } from '#angular/router';
import { AppComponent } from './app.component';
import { AppRouteGuard } from '#shared/auth/auth-route-guard';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { UsersComponent } from './users/users.component';
import { TenantsComponent } from './tenants/tenants.component';
import { RolesComponent } from 'app/roles/roles.component';
import { ChangePasswordComponent } from './users/change-password/change-password.component';
#NgModule({
imports: [
RouterModule.forChild([
{
path: '',
component: AppComponent,
children: [
{ path: 'home', component: HomeComponent, canActivate: [AppRouteGuard] },
{ path: 'users', component: UsersComponent, data: { permission: 'Pages.Users' }, canActivate: [AppRouteGuard] },
{ path: 'roles', component: RolesComponent, data: { permission: 'Pages.Roles' }, canActivate: [AppRouteGuard] },
{ path: 'tenants', component: TenantsComponent, data: { permission: 'Pages.Tenants' }, canActivate: [AppRouteGuard] },
{ path: 'about', component: AboutComponent },
{ path: 'update-password', component: ChangePasswordComponent }
]
}
])
],
exports: [RouterModule]
})
export class AppRoutingModule { }
root-routing.module.ts (also unchanged):
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
const routes: Routes = [
{ path: '', redirectTo: '/app/home', pathMatch: 'full' },
{
path: 'account',
loadChildren: 'account/account.module#AccountModule', // Lazy load account module
data: { preload: true }
},
{
path: 'app',
loadChildren: 'app/app.module#AppModule', // Lazy load account module
data: { preload: true }
}
];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class RootRoutingModule { }
Any ideas as to what is wrong? As I haven't changed anything, I wonder if the issue is with the environments/configurations?
in case anyone stumbled upon this question:
The problem does not occur when I run the application locally on my development machine.
The problem is related to the production server, the request is not being forwarded into your angular application properly
IIS
basically you need to install the url-rewrite and then configure a web.config file for the front-end site web.config configuration link 1 link 2
Apachi
link 1 link 2
I am developing nativescript-angular app that contains dataform in a module and calling this module using in lazy loading technique. Life is beautiful in Android, but the application exits immediately when I open this module in ios wihtout any error log!
The code is very simple and forward, I can't see where is the problem!
test.component.ts
import { Component, OnInit } from "#angular/core";
import { ActivatedRoute } from "#angular/router";
import { RadDataForm, DataFormEventData } from "nativescript-ui-dataform";
import { UserAddress } from "../../shared/data-services/address";
#Component({
selector: "test",
moduleId: module.id,
templateUrl: "./test.component.html",
styleUrls:["./test.component.css"]
})
export class TestComponent implements OnInit {
private _userAddress: UserAddress;
constructor() {
}
ngOnInit() {
this._userAddress = new UserAddress();
}
get userAddress(): UserAddress {
return this._userAddress;
}
}
test.component.html
<ActionBar class="action-bar">
<NavigationButton [nsRouterLink]="['../../home']" android.systemIcon="ic_menu_back"></NavigationButton>
<Label class="action-bar-title" text="Test"></Label>
</ActionBar>
<ScrollView tkExampleTitle tkToggleNavButton>
<StackLayout>
<RadDataForm tkExampleTitle tkToggleNavButton [source]="userAddress">
</RadDataForm>
</StackLayout>
</ScrollView>
Routing of this module
signup-routing.module.ts
import { NgModule } from "#angular/core";
import { Routes } from "#angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { ItemsComponent } from "./test/test.component";
export const COMPONENTS = [ItemsComponent ];
const routes: Routes = [
{ path: "", redirectTo: "testInfo" },
{ path: "testInfo", component: testComponent }
];
#NgModule({
imports: [NativeScriptRouterModule.forChild(routes)], // set the lazy loaded routes using forChild
exports: [NativeScriptRouterModule]
})
export class SignupRoutingModule {}
Then we have
signup.module.ts
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { COMPONENTS, SignupRoutingModule } from "./signup-routing.module";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptUIDataFormModule } from "nativescript-ui-dataform/angular";
#NgModule({
imports: [
NativeScriptCommonModule, // for rednering actionbar with lazy laoding
NativeScriptFormsModule,
SignupRoutingModule,
NativeScriptUIDataFormModule
],
declarations: [
...COMPONENTS
],
// providers: [SignupService],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class SignupModule { }
And the module is called using lazy loading in the basic routing file like this:
{ path: "signup", loadChildren: "~/app/signup/signup.module#SignupModule", outlet: "homeTab" }
Help is appreciated!
CODE ON GitHub
https://github.com/lighttiger/lazy
i implemented child route but its giving me error and i am not able to open even my parent page which i mentioned in code, here is my code, error is mentioned at the end
`import {Component} from '#angular/core';
#Component({
template:`<div style="width:350px;hight:200px;background-color:#00ff00">
<h1>Create Places</h1>
</div>
<a [routerLink]="['/placeDetail']">PlaceDetail</a>
<div>
<router-outlet></router-outlet>
</div>
`
})
export class PlaceComponent{}
`
import { ModuleWithProviders } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { DashboardComponent } from '../app/components/dashboard.component';
import {NeighbourhoodComponent} from '../app/components/neighbourhood.component';
import {UserProfileComponent} from '../app/components/userProfile.component';
import {PlaceComponent} from '../app/components/place.component';
import {PlaceDetailComponent} from '../app/components/placeDetail.component';
const appRoutes: Routes = [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full'
},
{
path: 'dashboard',
component: DashboardComponent
},
{
path:'neighbourhood',
component:NeighbourhoodComponent
},
{
path:'userprofile',
component:UserProfileComponent
},
{
path:'place',
component:PlaceComponent,
children:[
{
path:'placeDetail',
component:PlaceDetailComponent
}
]
}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
once i will click on link it should go to placeDetailComponent but it is giving me error
EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'place'
issue solved, i had Angular 2.1, just updated to 5 and it is working.
I want to use aurelia-auth in my app and also have a login page that is completely separate from the rest of the app. I have been following the tutorial at this link: https://auth0.com/blog/2015/08/05/creating-your-first-aurelia-app-from-authentication-to-calling-an-api/
The problem I am having is after I successfully login and attempt to route to the app, none of the routes are found. I get route not found regardless of what I put in for the login redirect url.
Here is my code:
app.js:
...
import { Router } from 'aurelia-router';
import { AppRouterConfig } from './router-config';
import { FetchConfig } from 'aurelia-auth';
...
#inject(..., Router, AppRouterConfig, FetchConfig)
export class App {
constructor(router, appRouterConfig, FetchConfig) {
this.router = router;
this.appRouterConfig = appRouterConfig;
this.fetchConfig = fetchConfig;
...
}
activate() {
this.fetchConfig.configure();
this.appRouterConfig.configure();
}
...
}
login.js:
import { AuthService } from 'aurelia-auth';
import { Aurelia } from 'aurelia-framework';
...
#inject(..., Aurelia, AuthService)
export class LoginScreen {
constructor(..., aurelia, authService) {
this.aurelia = aurelia;
this.authService = authService;
...
}
login() {
return this.authService.login(this.username, this.password)
.then(response => {
console.log("Login response: " + response);
this.aurelia.setRoot('app');
})
.catch(error => {
this.loginError = error.response;
alert('login error = ' + error.response);
});
}
...
}
main.js:
import config from './auth-config';
import { AuthService } from 'aurelia-auth';
import { Aurelia } from 'aurelia-framework';
...
export function configure(aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.developmentLogging()
.router()
.history()
.eventAggregator()
...
.plugin('aurelia-auth', (baseConfig) => {
baseConfig.configure(config);
});
let authService = aurelia.container.get(AuthService);
aurelia.start()
.then(a => {
if (authService.isAuthenticated()) {
a.setRoot('app');
} else {
a.setRoot('login');
}
});
}
auth-config.js:
var config = {
baseUrl: 'http://localhost:3001',
loginUrl: 'sessions/create',
tokenName: 'id_token',
//loginRedirect: '#/home' //looks like aurelia-auth defaults to #/ which is fine for me
}
export default config;
router-config.js:
import { AuthorizeStep } from 'aurelia-auth';
import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
#inject(Router)
export class AppRouterConfig {
constructor(router) {
this.router = router;
}
configure() {
console.log('about to configure router');
var appRouterConfig = function (config) {
config.title = 'My App';
config.addPipelineStep('authorize', AuthorizeStep);
config.map([
{
route: ['', 'home'],
name: 'home',
moduleId: '.components/home/home',
nav: true,
title: 'Home',
auth: true
},
{
route: ['employees'],
name: 'employees',
moduleId: './components/employees/employees',
nav: true,
title: 'Employees',
auth: true
}
]);
this.router.configure(appRouterConfig);
}
};
}
When loading the app, it successfully goes to login page and I'm able to successfully login and it tries to redirect, but I get this error in the console:
ERROR [app-router] Error: Route not found: /
at AppRouter._createNavigationInstruction (http://127.0.0.1:8080/jspm_packages/npm/aurelia-router#1.0.0-rc.1.0.1/aurelia-router.js:1039:29)
at AppRouter.loadUrl (http://127.0.0.1:8080/jspm_packages/npm/aurelia-router#1.0.0-rc.1.0.1/aurelia-router.js:1634:19)
at BrowserHistory._loadUrl (http://127.0.0.1:8080/jspm_packages/npm/aurelia-history-browser#1.0.0-rc.1.0.0/aurelia-history-browser.js:301:55)
at BrowserHistory.activate (http://127.0.0.1:8080/jspm_packages/npm/aurelia-history-browser#1.0.0-rc.1.0.0/aurelia-history-browser.js:200:21)
at AppRouter.activate (http://127.0.0.1:8080/jspm_packages/npm/aurelia-router#1.0.0-rc.1.0.1/aurelia-router.js:1689:20)
at eval (http://127.0.0.1:8080/jspm_packages/npm/aurelia-router#1.0.0-rc.1.0.1/aurelia-router.js:1670:21)
at AppRouter.registerViewPort (http://127.0.0.1:8080/jspm_packages/npm/aurelia-router#1.0.0-rc.1.0.1/aurelia-router.js:1672:10)
at new RouterView (http://127.0.0.1:8080/jspm_packages/npm/aurelia-templating-router#1.0.0-rc.1.0.1/router-view.js:112:19)
at Object.invokeWithDynamicDependencies (http://127.0.0.1:8080/jspm_packages/npm/aurelia-dependency-injection#1.0.0-rc.1.0.1/aurelia-dependency-injection.js:329:20)
at InvocationHandler.invoke (http://127.0.0.1:8080/jspm_packages/npm/aurelia-dependency-injection#1.0.0-rc.1.0.1/aurelia-dependency-injection.js:311:168)error # aurelia-logging-console.js:54log # aurelia-logging.js:37error # aurelia-logging.js:70(anonymous function) # aurelia-router.js:1637
aurelia-logging-console.js:54 ERROR [app-router] Router navigation failed, and no previous location could be restored.
I'm googling around quite a bit for answers to this, but having difficulty finding good answers. Anybody have any ideas? Any help is appreciated!
I think the problem is that you are configuring the router inside activate() method. In my opinion, there is no need to do this.
You can navigate to a route after resetting the root component:
this.aurelia.setRoot('./login')
.then((aurelia) => {
aurelia.root.viewModel.router.navigateToRoute('someLoginRoute');
});
You can also use the mapUnknownRoutes, which is very useful:
configureRouter(config, router) {
config.title = "Super Secret Project";
config.map([
{ route: [ '', 'screen-1'], moduleId: "./screen-1", nav: true, title: "Beginscherm" },
{ route: 'screen-2', name:'screen-2', moduleId: "./screen-2", nav: true, title: "Beginscherm" }
]);
config.mapUnknownRoutes(instruction => {
return './screen-1';
});
this.router = router;
}
See this example https://gist.run/?id=00b8b3745a480fb04184e8440e8be8c5. Pay attention at login/logout functions.
I hope this helps!
U can solve this by reloading or refreshing the app.
after setting app
ie.
a.setRoot('app');
location.reload();