When I run the following piece of code on my iOS emulator, the onTap() method is called twice. The exact same code run on my physical iPhone the onTap() is only called once. I know its the same code because tns run ios deploys to both simultaneously.
home.component.html:
<ActionBar title="Home" class="action-bar" visability="collapsed"></ActionBar>
<FlexboxLayout flexDirection="column" justifyContent="center" alignItems="center">
<Button (tap)="onTap($event)" class="fas btn btn-primary" text="Test"></Button>
</FlexboxLayout>
home.component.ts:
import { Component, OnInit } from '#angular/core';
import { Page } from 'ui/page';
#Component({
selector: 'home',
moduleId: module.id,
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
counter = 0;
constructor(private _page: Page) {}
ngOnInit(): void {
this._page.actionBarHidden = true;
}
onTap(args) {
this.counter++;
console.log('Tapped ' + this.counter + ' times!');
}
}
When I press button on emulator I get (note counter is not incremented):
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
Same code, on physical iPhone I get:
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
app-routing.module.ts:
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{
path: 'test',
loadChildren: '~/app/test/test.module#TestModule',
data: {
title: 'Test'
}
}
];
#NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule {}
package.json:
"dependencies": {
"#angular/animations": "~7.1.0",
"#angular/common": "~7.1.0",
"#angular/compiler": "~7.1.0",
"#angular/core": "~7.1.0",
"#angular/forms": "~7.1.0",
"#angular/http": "~7.1.0",
"#angular/platform-browser": "~7.1.0",
"#angular/platform-browser-dynamic": "~7.1.0",
"#angular/router": "~7.1.0",
"nativescript-angular": "~7.1.0",
"nativescript-ngx-fonticon": "~4.2.0",
"nativescript-orientation": "~2.2.1",
"nativescript-sqlite": "~2.2.6",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-chart": "~3.11.1",
"nativescript-ui-listview": "~5.1.0",
"reflect-metadata": "~0.1.8",
"rxjs": "~6.3.0",
"tns-core-modules": "~5.1.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "~7.1.0",
"#nativescript/schematics": "~0.5.0",
"#ngtools/webpack": "~7.1.0",
"codelyzer": "~4.5.0",
"nativescript": "~5.1.0",
"nativescript-dev-sass": "~1.6.0",
"nativescript-dev-typescript": "~0.7.0",
"nativescript-dev-webpack": "~0.19.0",
"tslint": "~5.11.0"
},
Things I've tried:
Delete app from emulator
Delete hooks,node_modules,platforms and re-run tns run ios
Created a similar app in the playground, and everything is fine (onTap() is only called once on the emulator).
Any ideas?
It was something with filewatcher. Two instances of it running was deploying the same app 2x on device. Hard to explain.
I Hardware > Erase all content and settings.., killed my terminal, opened a new one and ran tns run ios.
Related
I'm new with NativeScript and I want to use a state management NGXS and implement to my app. I have installed NGXS with NPM: #ngxs/store #ngxs/logger-plugin and #ngxs/devtools-plugin.
So I added those NGXS module to my app.module.
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptUISideDrawerModule } from "nativescript-ui-sidedrawer/angular";
import { NgxsModule } from '#ngxs/store';
import { NgxsLoggerPluginModule } from '#ngxs/logger-plugin';
import { NgxsReduxDevtoolsPluginModule } from '#ngxs/devtools-plugin';
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { PetState } from './_ngxs/pet/pet.state';
#NgModule({
bootstrap: [
AppComponent
],
imports: [
AppRoutingModule,
NativeScriptModule,
NativeScriptUISideDrawerModule,
NgxsModule.forRoot([
//if i uncomment PetState, in console log show me error, Failed to find module: "./pet.actions"
// PetState
]),
//if i uncomment `NgxsLoggerPluginModule.forRoot()`, in console log show me error, Failed to find module: "#ngxs/logger-plugin
// NgxsLoggerPluginModule.forRoot(),
//if i uncomment `NgxsReduxDevtoolsPluginModule.forRoot()`, in console log show me error, Failed to find module: "#ngxs/devstool-plugin
// NgxsReduxDevtoolsPluginModule.forRoot()
],
declarations: [
AppComponent
],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class AppModule { }
After I added the ngxs module, I got 2 issues.
under NgxsModule.forRoot if I uncomment PetState it throw me error in console log, Failed to find module: "./pet.actions". Please refer
If I uncomment NgxsLoggerPluginModule.forRoot() / NgxsReduxDevtoolsPluginModule.forRoot() I will get error in console log and saying failed to find module #ngxs/logger-plugin / #ngxs/devstool-plugin
below is pet.state.ts codes
import { State, Action, Selector, StateContext } from '#ngxs/store';
import { Pet } from './pet.model';
import { AddPet, RemovePet } from './pet.actions';
export class PetStateModel {
pets: Pet[];
}
#State<PetStateModel>({
name: 'Pet',
defaults: {
pets: []
}
})
export class PetState {
#Selector()
static getPet(state: PetStateModel) {
return state.pets;
}
#Action(AddPet)
addPet({getState, patchState}: StateContext<PetStateModel>, { payload }: AddPet) {
const state = getState();
patchState({
pets: [...state.pets, payload]
})
}
#Action(RemovePet)
removePet({getState, patchState}: StateContext<PetStateModel>, { payload }: RemovePet) {
const state = getState();
patchState({
pets: state.pets.filter(a => a.name !== payload )
})
}
}
I really need someone can give some hand to help me fix the issues,
thanks,
Updated
here is my package.json
{
"nativescript": {
"id": "org.nativescript.pledgeCareSample",
"tns-android": {
"version": "5.2.1"
},
"tns-ios": {
"version": "5.2.0"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"scripts": {
"lint": "tslint \"src/**/*.ts\""
},
"dependencies": {
"#angular/animations": "~7.2.0",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/forms": "~7.2.0",
"#angular/http": "~7.2.0",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"#ngxs/storage-plugin": "^3.4.3",
"#ngxs/store": "^3.4.3",
"nativescript-angular": "~7.2.1",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-sidedrawer": "~5.1.0",
"nativescript-unit-test-runner": "^0.6.0",
"reflect-metadata": "~0.1.12",
"rxjs": "~6.3.0",
"tns-core-modules": "~5.2.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "~7.2.0",
"#nativescript/schematics": "~0.5.0",
"#ngtools/webpack": "~7.2.0",
"#ngxs/devtools-plugin": "^3.4.3",
"#ngxs/logger-plugin": "^3.4.3",
"#types/jasmine": "^3.3.12",
"codelyzer": "~4.5.0",
"karma": "4.0.1",
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "0.4.0",
"nativescript-dev-sass": "~1.6.0",
"nativescript-dev-typescript": "~0.8.0",
"nativescript-dev-webpack": "~0.20.0",
"tslint": "~5.11.0"
},
"gitHead": "f548ec926e75201ab1b7c4a3a7ceefe7a4db15af",
"readme": "NativeScript Application"
}
Ok I found the solution. After few hours I found this solution here and with my solutions
Just need to remove node_modules, hook and platform folder then npm i and add the platform for both ios and android.
and 1 more thing I am not sure why, I uninstalled for #ngxs/logger-plugin and #ngxs/devtools-plugin and reinstall back to the dependency not in dev dependency.
anyway, for now it work for me.
I am getting error in my app
error TS2339: Property 'filter' does not exist on type 'Observable'
I tried to import vaeious things but it didn't worked.
My component ts file
import { Component, OnInit } from '#angular/core';
import {
Router,
ActivatedRoute,
NavigationEnd,
Params,
PRIMARY_OUTLET
} from '#angular/router';
import 'rxjs/add/operator/filter';
ngOnInit() {
const ROUTE_DATA_BREADCRUMB: string = 'breadcrumb';
//subscribe to the NavigationEnd event
this.router.events
.filter(event => event instanceof NavigationEnd)
.subscribe(event => {
//set breadcrumbs
let root: ActivatedRoute = this.activatedRoute.root;
this.breadcrumbs = this.getBreadcrumbs(root);
console.log(this.breadcrumbs);
});
}
My package.json
"dependencies": {
"#agm/core": "^1.0.0-beta.5",
"#angular/animations": "^6.1.8",
"#angular/common": "^6.0.3",
"#angular/compiler": "^6.0.3",
"#angular/core": "^6.0.3",
"#angular/forms": "^6.0.3",
"#angular/http": "^6.0.3",
"#angular/platform-browser": "^6.0.3",
"#angular/platform-browser-dynamic": "^6.0.3",
"#angular/router": "^6.0.3",
"bootstrap3": "^3.3.5",
"core-js": "^2.5.4",
"jquery": "^3.3.1",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
I don't know whats wrong but getting this error
error TS2339: Property 'filter' does not exist on type 'Observable'
Silly mistake just need to pipe
ngOnInit() {
this.router.events.pipe(
filter(event => event instanceof NavigationEnd)
).subscribe(event => {
//set breadcrumbs
let root: ActivatedRoute = this.activatedRoute.root;
this.breadcrumbs = this.getBreadcrumbs(root);
console.log(this.breadcrumbs);
});
}
and import
import { filter } from 'rxjs/operators';
After migrating from Angular 5 to Angular 6 all my Material component do not work anymore - again... ...yet this time I am really clueless about what could cause the problem anymore. I invested half a day investigating and created a stripped-down project in order to reproduce the problem in its essence.
Let me show you the various file contents:
package.json
{
"name": "xxx",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.9",
"#angular/cdk": "^6.4.0",
"#angular/common": "^6.0.9",
"#angular/compiler": "^6.0.9",
"#angular/core": "^6.0.9",
"#angular/forms": "^6.0.9",
"#angular/http": "^6.0.9",
"#angular/material": "^6.4.0",
"#angular/platform-browser": "^6.0.9",
"#angular/platform-browser-dynamic": "^6.0.9",
"#angular/platform-server": "^6.0.9",
"#angular/router": "^6.0.9",
"#ngtools/webpack": "1.8.0",
"#types/node": "~6.0.60",
"#types/webpack-env": "1.13.0",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"codelyzer": "~3.2.0",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"preboot": "4.5.2",
"protractor": "~5.1.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "^6.2.2",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.7.2",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular/cli": "^6.0.8",
"#angular/compiler-cli": "^6.0.9",
"#angular/language-service": "^6.0.9",
"#types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0"
}
}
app.module
import { NgModule } from '#angular/core';
import { MatDialogModule } from '#angular/material';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { AppComponent } from './components/app/app.component';
import { MessageFormComponent } from './components/common/forms/message.component';
#NgModule({
declarations: [
AppComponent,
MessageFormComponent,
],
imports: [
CommonModule,
MatDialogModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: MessageFormComponent },
{ path: '**', redirectTo: 'home' }
]),
]
})
export class AppModuleShared {
}
message.component.ts
import { Component } from '#angular/core';
import { MatDialog, MAT_DIALOG_DATA } from '#angular/material';
#Component({
selector: 'message-form',
template: 'blubb',
})
export class MessageFormComponent {
constructor(private alert: MatDialog) { } // this line causes the problem
}
As soon as I make ANYTHING with the material - this error occurs. I am good in programming angular programs - not so good in fiddling around with the NEVER WORKING infrastructure... ;-)
while trying to use RadListView from TelerikUI, I faced an error I cannot get a hang on. According to the angular samples, I
imported the module in my submodule.ts file
import { NativeScriptUIListViewModule } from "nativescript-telerik-ui/listview/angular";
and
#NgModule({
imports: [
NativeScriptModule,
NativeScriptI18nModule,
NativeScriptRouterModule,
subRouting,
NativeScriptUIListViewModule,
],
declarations: [
ListPageComponent,
],
exports: [
]
})
export class SubModule {}
created the data object definition in the ListPageComponent
class DataItem {
constructor(public id: string, public type: string) { }
}
and wrote my component class
#Component({
selector: "list",
moduleId: module.id,
templateUrl: "list.page.html",
styleUrls: ["list.page.css"]
})
export class ListPageComponent implements OnInit {
public _dataItems: DataItem[] = [
{id: "1", type: "A"},
{id: "2", type: "A"},
{id: "3", type: "A"}
];
get dataItems(): ObservableArray<DataItem> {
return new ObservableArray(this._dataItems);
}
constructor(
private _pageRoute: PageRoute,
private _routerExtensions: RouterExtensions,
private _page: Page
){
}
ngOnInit(): void {
}
}
finally, trying to render as defined with
<GridLayout columns="*" rows="*">
<RadListView [items]="dataItems" col="0" row="1">
<ng-template tkListItemTemplate let-item="item">
<GridLayout columns="auto" rows="auto">
<Label class="descriptionLabel" [text]="item.type" col="0" row="0"></Label>
</GridLayout>
</ng-template>
</RadListView>
</GridLayout>
The example works with the basic listview, but switching to the RadListView throws
An uncaught Exception occured on "main" thread. com.tns.NativeScriptException:
Calling js method onCreateViewHolder failed
Type Error: Cannot read property 'setLayoutParams' of undefined File: "file:///data/data/org.nativescript.myapp/files/app/tns_modules/nativescript-telerik-ui/listview/listview.js, line: 102 column: 42
StackTrace:
Frame: function:'ListViewAdapter.onCreateViewHolder', file"file:///data/data/org.nativescript.myapp/files/app/tns_modules/nativescript-telerik-ui/listview/listview.js, line: 102 column: 43
at com.tns.Runtime.callJSMethodNative (Native Method) [...]
on my android emulator (no chance to test on ios yet)
It seems, I'm doing a basic thing wrong with RadListView, although I kept fully aligned with the nativescript-ui-samples for angular app.
My package.json excerpt
"nativescript": {
"id": "org.nativescript.myapp",
"tns-android": {
"version": "3.1.1"
},
"tns-ios": {
"version": "3.1.0"
}
},
"dependencies": {
"#angular/animations": "~4.2.0",
"#angular/common": "~4.2.0",
"#angular/compiler": "~4.2.0",
"#angular/core": "~4.2.0",
"#angular/forms": "~4.2.0",
"#angular/http": "~4.2.0",
"#angular/platform-browser": "~4.2.0",
"#angular/router": "~4.2.0",
"moment": "^2.18.1",
"nativescript-angular": "~4.2.0",
"nativescript-gif": "^2.0.0",
"nativescript-i18n": "^0.2.2",
"nativescript-telerik-ui": "^3.1.0",
"nativescript-theme-core": "~1.0.4",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.4.2",
"tns-core-modules": "~3.1.1",
"zone.js": "~0.8.2"
},
Any hints are highly appreciated.
Thx.
you need to update everything to the latest version tns plugin update. also update the android and ios versions to 3.2.0
Below is the simple Angular 2 code that should show dialog box in the middle out of the box. Instead dialog box show at the bottom.
I am using "angular-cli": "1.0.0-beta.24" and "#angular/material": "^2.0.0-beta.1"
Can anybody help why this is happening?
import { Component } from '#angular/core';
import {MdDialog,MdDialogRef,MdDialogConfig} from '#angular/material';
#Component({
selector: 'app-root',
template: `
<md-sidenav-container style="width:200px;height:500px;">
<md-sidenav mode="side" opened="true" #sidenav>
<md-nav-list>
<a md-list-item (click)="newItem()">
New
</a>
<a md-list-item>
Refresh
</a>
<a md-list-item>
Delete
</a>
</md-nav-list>
</md-sidenav>
</md-sidenav-container>
`,
})
export class AppComponent {
title = 'app works!';
constructor(public dialog: MdDialog) {}
newItem()
{
let dialogRef=this.dialog.open(RecordDialogComponent);
dialogRef.afterClosed().subscribe(result => {
});
}
}
#Component({
selector: 'record-dialog',
template: ` <h1 md-dialog-title>New Item</h1>
<md-dialog-actions>
<button (click)="dialogRef.close('save')">Save</button>
<button md-dialog-close>Cancel</button>
</md-dialog-actions>
`
})
export class RecordDialogComponent{
public title: string;
public message: string;
constructor(public dialogRef: MdDialogRef<RecordDialogComponent>) { }
}
Below is the package.json
{
"name": "materialt2",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "^2.3.1",
"#angular/compiler": "^2.3.1",
"#angular/core": "^2.3.1",
"#angular/forms": "^2.3.1",
"#angular/http": "^2.3.1",
"#angular/material": "^2.0.0-beta.1",
"#angular/platform-browser": "^2.3.1",
"#angular/platform-browser-dynamic": "^2.3.1",
"#angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"#angular/compiler-cli": "^2.3.1",
"#types/jasmine": "2.5.38",
"#types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.24",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3"
}
}
Try this
const dialogRef = this.dialog.open(DialogComponentName, {
width: '250px'
position: { bottom: '0'}
});
You can also add left: 0 etc.
I had the same issue as you. This post helped me to solve it (although I think this isn't intended because it isn't described anywhere I looked): Angular2 Material: Md-Menu opens below router outlet
You need to include a theme from Angular Material as described here: https://github.com/angular/material2/blob/master/guides/theming.md
That fixed it for me.
You can change modal position using this code. Put this inside your md-dialog component.
import { MdDialog, MdDialogConfig, MdDialogRef } from '#angular/material';
constructor(public dialogRef: MdDialogRef<any>) { }
ngOnInit() {
this.dialogRef.updatePosition({ top: '25px', left: '25px' });
}
you can use updatePosition method anywhere inside dialog component.
for more information check this link https://material.angular.io/components/component/dialog