I simply install lottie plugin im using it in app.component.ts to show the screen but its showing error
TypeError: this.lottieSplashScreen.show(...).then is not a function
can any one please tell the issue i need to show it like splash screen thanks.
app.component.ts
import { Component } from '#angular/core';
import { Platform } from '#ionic/angular';
import { SplashScreen } from '#ionic-native/splash-screen/ngx';
import { StatusBar } from '#ionic-native/status-bar/ngx';
import { LottieSplashScreen } from '#ionic-native/lottie-splash-screen/ngx';
#Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
public appPages = [
{
title: 'Home',
url: '/home',
icon: 'home'
},
{
title: 'List',
url: '/list',
icon: 'list'
}
];
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private lottieSplashScreen: LottieSplashScreen
) {
this.initializeApp();
this.lottieSplashScreen.show('https://assets10.lottiefiles.com/packages/lf20_CLhLRL/data.json', false, 1024, 768)
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
});
}
}
ionic native always should be in device ready :
import { LottieSplashScreen } from '#ionic-native/lottie-splash-screen/ngx';
import { Platform } from '#ionic/angular';
class ...
constructor(public plt: Platform, private lottieSplashScreen: LottieSplashScreen){
plt.ready().then(()=>{
this.lottieSplashScreen.show('https://assets10.lottiefiles.com/packages/lf20_CLhLRL/data.json', false, 1024, 768)
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
}
});
}
Related
I've created a new app using Ionic5 with a menu. I'm trying to use a Footer on multiple pages (now only on Home page). First I've created a SharedModule and imported in the imports' array of the app.module.ts. I've added the footer component in the declarations' and exports' array of the shared.module.ts. Also I added SharedModule in the imports' array of each page.module.ts, and finally adding <app-footer> in each page.html.
It works as expected, showing the footer in all pages. But now I need to control (on/off) this footer from my app.component, in response to a specific event, for example, when internet is not available (this part is not a problem).
footer.component.ts
import { Component, OnInit } from '#angular/core';
import { FooterService } from 'src/app/footer.service';
#Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss'],
})
export class FooterComponent implements OnInit {
public FooterEnabled: boolean= false;
constructor() { }
ngOnInit() {
}
}
The FooterEnabled variable control if the footer is showed or not and must be modifiable from the app.component
footer.component.html
<div class="footer-conn" *ngIf="FooterEnabled">
Alert!
</div>
sharedfooter.module.ts
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FooterComponent } from '../components/footer/footer.component';
#NgModule({
declarations: [FooterComponent],
imports: [
CommonModule
],
exports: [
FooterComponent, CommonModule
]
})
export class SharedFooterModule { }
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 { Network } from '#ionic-native/network/ngx';
import { SharedFooterModule } from './shared/sharedfooter.module';
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
SharedFooterModule
],
providers: [
StatusBar,
SplashScreen,
Network,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
app.component.ts
import { Component, OnInit } from '#angular/core';
import { Platform } from '#ionic/angular';
import { SplashScreen } from '#ionic-native/splash-screen/ngx';
import { StatusBar } from '#ionic-native/status-bar/ngx';
import { Network } from '#ionic-native/network/ngx';
#Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit {
public selectedIndex = 0;
public appPages = [
{
title: 'Página 1',
url: 'home',
icon: 'mail'
},
{
title: 'Página 2',
url: 'pagina2',
icon: 'paper-plane'
},
{
title: 'Página 3',
url: 'pagina3',
icon: 'heart'
}
];
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private network: Network
) {
this.initializeApp();
}// Fin constructor
no_internet() {
alert("No internet!")
// In this point make FooterEnabled = true (from the footer component)
}
si_internet() {
alert("Whith internet!")
//In this point make FooterEnabled = false (from the footer component)
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
ngOnInit() {
let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
setTimeout(() => {
if (this.network.type !== 'none') {
this.si_internet();
}
else {
this.no_internet();
}
}, 1000);
});
// watch network for a connection
let connectSubscription = this.network.onConnect().subscribe(() => {
setTimeout(() => {
if (this.network.type !== 'none') {
this.si_internet();
}
else {
this.no_internet();
}
}, 3000);
});
const path = window.location.pathname.split('/')[1];
if (path !== undefined) {
this.selectedIndex = this.appPages.findIndex(page => page.title.toLowerCase() === path.toLowerCase());
}
}
}
home.module.ts (as an example)
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FormsModule } from '#angular/forms';
import { IonicModule } from '#ionic/angular';
import { HomePageRoutingModule } from './home-routing.module';
import { HomePage } from './home.page';
import { SharedFooterModule } from '../shared/sharedfooter.module';
#NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
HomePageRoutingModule,
SharedFooterModule
],
declarations: [HomePage]
})
export class HomePageModule {}
I've tried with a service imported in the footer.component and app.component.ts that implements observables, but it didn't work. I will appreciate your contributions!!
maybe you can do it like bellow, add input to your footer component :
footer.component.ts
import { Component, OnInit, Input } from '#angular/core';
#Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss'],
})
export class FooterComponent implements OnInit {
#Input() FooterEnabled : string;
//public FooterEnabled: boolean= false;
constructor() { }
ngOnInit() {
}
}
footer.component.ts
<div class="footer-conn" *ngIf="FooterEnabled == 'on'">
Alert!
</div>
on your app.component.ts add new varibale status:
no_internet() {
alert("No internet!")
this.status = 'on'
}
si_internet() {
alert("Whith internet!")
this.status = 'off'
}
put it on app.component.html as :
<app-footer FooterEnabled="status" ></app-footer>
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
I am sending a notification that navigates the user to a specific screen when the notification is clicked.
This works perfectly when the app is opened or running in the background, however, when the app is closed onNotification is not being called.
I am using react native push notification and wix react native navigation V3.
I notice the problem by putting a console log inside on notification and it was never called.
In index.js I have the follwing code
import { start } from './App';
start();
In App.js
import React from 'react';
import { Navigation } from 'react-native-navigation';
import { Provider } from 'react-redux';
import configureStore from './src/configureStore';
import { configurePush } from './src/utils/push-notifications';
import Login from './src/components/views/Login';
import Home from './src/components/views/Home';
import Cart from './src/components/views/Cart';
import CartDetail from './src/components/views/Cart/Detail';
import Orders from './src/components/views/Orders';
... the rest of the screens
const store = configureStore();
configurePush(store);
export function registerScreens() {
Navigation.registerComponent('provi.Login', () => (props) => (
<Provider store={store}>
<Login {...props} />
</Provider>
), () => Login);
Navigation.registerComponent('provi.Home', () => (props) => (
<Provider store={store}>
<Home {...props} />
</Provider>
), () => Home);
Navigation.registerComponent('provi.Cart', () => (props) => (
<Provider store={store}>
<Cart {...props} />
</Provider>
), () => Cart);
... the rest of the screens
}
export function start() {
registerScreens();
Navigation.events().registerAppLaunchedListener(async () => {
Navigation.setRoot({
root: {
stack: {
children: [{
component: {
name: 'provi.Login',
options: {
animations: {
setStackRoot: {
enabled: true
}
},
topBar: {
visible: false,
drawBehind: true,
background: {
color: '#30DD70'
},
},
bottomTabs: {
visible: false
}
}
}
}],
}
}
});
});
}
Then the configuration of the notification is the following:
import PushNotificationIOS from "#react-native-community/push-notification-ios";
import { Navigation } from 'react-native-navigation';
import PushNotification from 'react-native-push-notification';
import DeviceInfo from 'react-native-device-info';
import fetchApi from "../store/api";
import { addNotification } from '../store/notifications/actions';
import { SENDER_ID } from '../constants';
export const configurePush = (store) => {
PushNotification.configure({
onRegister: function(token) {
if (token) {
const registerData = {
token: token.token,
uid: DeviceInfo.getUniqueID(),
platform: token.os
}
// console.log(registerData);
fetchApi('/notificaciones/register', 'POST', registerData).catch(err => console.log(err))
}
},
onNotification: function(notification) {
if (notification) {
store.dispatch(addNotification(notification)); // Almacena la notification
const action = notification.data.click_action;
if (action === 'oferta') {
const remotePost = notification.data.data;
Navigation.setRoot({
root: {
stack: {
children: [{
component: {
name: 'provi.Home',
options: {
animations: {
setStackRoot: {
enabled: true
}
},
topBar: {
visible: true,
drawBehind: false,
},
passProps: {
test: 'test',
notification: remotePost
}
}
}
}],
}
}
});
} else if (action === 'seller') {
const remoteSeller = notification.data.data;
Navigation.push('Home', {
component: {
name: 'provi.Seller',
passProps: {
id: remoteSeller._id,
featureImage: remoteSeller.featureImage
},
options: {
topBar: {
title: {
text: 'Nueva Marca!'
}
},
bottomTabs: {
visible: false,
drawBehind: true
}
}
}
});
} else if (action === 'sellerClosingSoon') {
const remoteSeller = notification.data.data;
Navigation.push('Home', {
component: {
name: 'provi.ClosingSoon',
passProps: {
id: remoteSeller._id,
featureImage: remoteSeller.featureImage
},
options: {
topBar: {
title: {
text: 'Marcas que cierran pronto'
}
},
bottomTabs: {
visible: false,
drawBehind: true
}
}
}
});
}
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
senderID: SENDER_ID,
popInitialNotification: true,
requestPermissions: true
});
}
I am expecting to see the console.log at least but it's not happening.
What is the correct setup for RNN V3 with RN push notification?
the notifications are two types: background and foreground.
You use foreground notifications. But when an app is closed and you receive a new notification your callback cannot be fired.
You should use something like getInitialNotification to get the notification data.
https://github.com/zo0r/react-native-push-notification/blob/master/component/index.android.js#L19
I hope that helps.
Thanks
I am using formbuilder.group to create reactive form with the formcontrol name in ngOnInit() and made a get function for name, when I run ng test I get error as below
I have created the test case for my component using Simon Test extension
I tried importing ReactiveFormsModule, CommonModule in spec.ts
I tried changing form.get('name') to form.controls.name
Error in karma-test runner
Test1Component ngOnInit makes expected calls
TypeError: this.form.get is not a function
TypeError: this.form.get is not a function
at Test1Component.get [as name] (http://localhost:9877/_karma_webpack_/webpack:/src/app/test1/test1.component.ts:27:22)
at Test1Component../src/app/test1/test1.component.ts.Test1Component.printVal (http://localhost:9877/_karma_webpack_/webpack:/src/app/test1/test1.component.ts:23:22)
at Test1Component.SpyStrategy.exec (http://localhost:9877/absoluteC:/Users/ratnsing/Desktop/Ratnesh/Angular7/Xv1/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:5083:19)
at Test1Component.spy (http://localhost:9877/absoluteC:/Users/ratnsing/Desktop/Ratnesh/Angular7/Xv1/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:4873:44)
at Test1Component.<anonymous> (http://localhost:9877/absoluteC:/Users/ratnsing/Desktop/Ratnesh/Angular7/Xv1/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:4849:20)
at Test1Component.printVal (http://localhost:9877/absoluteC:/Users/ratnsing/Desktop/Ratnesh/Angular7/Xv1/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:4890:50)
at Test1Component../src/app/test1/test1.component.ts.Test1Component.ngOnInit (http://localhost:9877/_karma_webpack_/webpack:/src/app/test1/test1.component.ts:19:10)
at UserContext.<anonymous> (http://localhost:9877/_karma_webpack_/webpack:/src/app/test1/test1.component.spec.ts:28:17)
at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9877/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:391:1)
at ProxyZoneSpec.push../node_modules/zone.js/dist/zone-testing.js.ProxyZoneSpec.onInvoke (http://localhost:9877/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:289:1)
test1.component.ts
import { Component, OnInit } from '#angular/core';
import { FormGroup, FormBuilder } from '#angular/forms';
#Component({
selector: 'app-test1',
templateUrl: './test1.component.html',
styleUrls: ['./test1.component.css']
})
export class Test1Component implements OnInit {
form: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.form = this.formBuilder.group({
name: ['Init Value']
});
this.printval();
}
printVal() {
console.log(this.name);
}
get name() {
return this.form.get('name');
}
}
test1.component.spec.ts
import { ComponentFixture, TestBed } from '#angular/core/testing';
import { NO_ERRORS_SCHEMA } from '#angular/core';
import { FormBuilder } from '#angular/forms';
import { Test1Component } from './test1.component';
describe('Test1Component', () => {
let component: Test1Component;
let fixture: ComponentFixture<Test1Component>;
beforeEach(() => {
const formBuilderStub = { group: object1 => ({}) };
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [Test1Component],
providers: [{ provide: FormBuilder, useValue: formBuilderStub }]
});
fixture = TestBed.createComponent(Test1Component);
component = fixture.componentInstance;
});
it('can load instance', () => {
expect(component).toBeTruthy();
});
describe('ngOnInit', () => {
it('makes expected calls', () => {
const formBuilderStub: FormBuilder = fixture.debugElement.injector.get(
FormBuilder
);
spyOn(component, 'printVal').and.callThrough();
spyOn(formBuilderStub, 'group').and.callThrough();
component.ngOnInit();
expect(component.printVal).toHaveBeenCalled();
expect(formBuilderStub.group).toHaveBeenCalled();
});
});
});
I found that .get is a part of AbstractControl property,
expecting al the test cases to pass...
Can u try:
import { async, ComponentFixture, TestBed } from '#angular/core/testing';
import { ReactiveFormsModule, FormBuilder, FormsModule } from '#angular/forms';
import { CommonModule } from '#angular/common';
beforeEach(async(() => {
const formBuilderStub = { group: object1 => ({}) };
TestBed.configureTestingModule({
imports: [CommonModule,ReactiveFormsModule,FormsModule],
schemas: [NO_ERRORS_SCHEMA],
declarations: [Test1Component],
providers: [FormBuilder]
}).compileComponents();
fixture = TestBed.createComponent(Test1Component);
component = fixture.componentInstance;
}));
Remove overriding of FormBuilder service
providers: [{ provide: FormBuilder, useValue: formBuilderStub }]
Import ReactiveFormsModule in TestBed
Add .compileComponents();
Put it in async block
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() {
}
}