I try to use ion-textarea instead of ion-input for make a form to modify my item. I can't set a value with ngmodel or value that are from my typescript code.
I try (textNote is the variable in my ts):
ngmodel="textNote" => X
ngmodel="textNote" value="textNote" => X
ngmodel="textNote" value="{{textNote}}" => X
this kind of combination never works
This is my html
<ion-header>
<ion-toolbar color="primary">
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>
<h6>
Modify Audio Text
</h6>
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-item>
<ion-label color="primary" >Hour</ion-label>
<ion-datetime display-format="HH:mm" [(ngModel)]="hour"></ion-datetime>
</ion-item>
<ion-item>
<ion-label color="primary">Date</ion-label>
<ion-datetime display-format="DD MMM YYYY" [(ngModel)]="date"></ion-datetime>
</ion-item>
<ion-item>
<ion-label color="primary" position="stacked">Text</ion-label>
<ion-textarea type="text" [(ngModel)]="textNote"></ion-textarea>
</ion-item>
<ion-button expand="block" shape="round" (click)="modifyElement()">Modify</ion-button>
</ion-content>
This my typescript
import { DatabaseService } from './../services/database.service';
import { ActivatedRoute, Router } from '#angular/router';
import { Component } from '#angular/core';
#Component({
selector: 'app-note-text-modify',
templateUrl: './note-text-modify.page.html',
styleUrls: ['./note-text-modify.page.scss'],
})
export class NoteTextModifyPage{
date: String;
hour: String;
id:Number;
textNote: String = "";
constructor(private route:ActivatedRoute,private router:Router,private db:DatabaseService) {
this.id = +(this.route.snapshot.paramMap.get('id'));
this.db.getNote(this.id).then(res=>{
this.date=res.date;
this.hour=res.hour;
});
}
modifyElement(){
this.db.updateNoteTimeText(this.id,this.date,this.hour,this.textNote)
.then(_=>this.router.navigateByUrl('/tabs/note'));
}
}
Related
The ion-back-button I am trying to use on this page refuses to appear. There is nothing in the start slot when I should get a " < Back " button appearing.
selected_card.page.html
<ion-toolbar>
<ion-buttons slot='start'>
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{restaurant.name}}</ion-title>
</ion-toolbar>
</ion-header>
selected_card.page.ts
import { ModalController, NavParams } from '#ionic/angular';
import { RestaurantsService } from '../services/restaurants.service';
#Component({
selector: 'app-selected-card',
templateUrl: './selected-card.page.html',
styleUrls: ['./selected-card.page.scss'],
})
export class SelectedCardPage implements OnInit {
// value: string;
restaurant: any;
constructor(private restaurantsService: RestaurantsService,
private modalCtrl: ModalController,
private navParams: NavParams) { }
ngOnInit() {
this.restaurant = this.navParams.get('restaurant');
console.log(this.restaurant);
}
selectRestaurant() {
console.log(this.customRestaurant)
this.customRestaurant()
}
dismiss() {
this.modalCtrl.dismiss();
}
}
Let me know if y'all have questions! Really cannot figure out why this will not work when it works every other time I use it.
I am not clear about your question though if you wanted ion-back-button you are not using this component inside your ion-buttons. ion-back-button should be used instead of ion-button ...
<ion-toolbar>
<ion-buttons slot='start'>
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{restaurant.name}}</ion-title>
</ion-toolbar>
</ion-header>
This should work for showing back button.
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>
Room info page
</ion-title>
</ion-toolbar>
</ion-header>
looking to display title values from json file. but in the HTML it can only dig down to an array and displays object: object. I'm looking to find the title which is located under sections.0.foreground.title. do I need to add something to my home.ts or can it all be in the HTML? thanks
cannot read property'0" of undefined
new html error
Home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<form [formGroup]="storymap" (ngSubmit)="logForm()">
<ion-item>
<ion-label color="primary">URL</ion-label>
<ion-input type="text" placeholder="Storymap URL" formControlName="storymapurl" [(ngModel)]="inputName"></ion-input>
</ion-item>
<ion-item> *ngFor="let item of result.values.sections">
<button ion-button (click) = "getData()">Get Data</button>
<ion-row>Title:{{item.foreground.title}}</ion-row>
</ion-item>
<ion-item>
<ion-label>storymap</ion-label>
<ion-input type="text" formControlName="title"></ion-input>
</ion-item>
<ion-item>
<ion-label>Description</ion-label>
<ion-textarea formControlName="description"></ion-textarea>
</ion-item>
<button ion-button type="submit" [disabled]="!storymap.valid">Submit</button>
</form>
home.ts
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import {Validators, FormBuilder, FormGroup } from '#angular/forms';
import {HttpClient,HttpHeaders} from '#angular/common/http'
import { Observable } from 'rxjs/Observable';
import $ from 'jquery'
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private storymap : FormGroup;
result:any= [];
data: Observable<any>;
public inputName: string;
constructor(public navCtrl: NavController, public http:HttpClient, private formBuilder: FormBuilder) {
this.storymap = this.formBuilder.group({
storymapurl: [''],
title: ['', Validators.required],
description: [''],
});
}
getData(){
this.inputName;
console.log('here', this.inputName)
this.data = this.http.get(this.inputName);
this.data.subscribe(data => {
this.result = data;
// console.log(data)
this.title = data.sections[0].foreground.title
console.log(this.title)
});
}
logForm(){
console.log(this.storymap.value)
}
}
So after our convo I think I understood your use case:
* user clicks Button getData()
* users sees data's title for the first item in sections?
Then you need to do:
<form [formGroup]="storymap" (ngSubmit)="logForm()">
<ion-item>
<ion-label color="primary">URL</ion-label>
<ion-input type="text" placeholder="Storymap URL" formControlName="storymapurl" [(ngModel)]="inputName"></ion-input>
</ion-item>
<ion-item>
<button ion-button (click) = "getData()">Get Data</button>
<ion-row>Title:{{title}}</ion-row>
</ion-item>
<ion-item>
<ion-label>storymap</ion-label>
<ion-input type="text" formControlName="title"></ion-input>
</ion-item>
<ion-item>
<ion-label>Description</ion-label>
<ion-textarea formControlName="description"></ion-textarea>
</ion-item>
<button ion-button type="submit" [disabled]="!storymap.valid">Submit</button>
</form>
And in your ts file:
export class HomePage {
private storymap : FormGroup;
private title: string;
private inputName: string = "https://www.arcgis.com/sharing/rest/content/items/b9ec967ce39a49cd8de6fd24aa14d477/data?f=json"
private result: any;
constructor(public navCtrl: NavController, public http:HttpClient, private formBuilder: FormBuilder) {
this.storymap = this.formBuilder.group({
storymapurl: [''],
title: ['', Validators.required],
description: [''],
});
}
getData(){
this.http.get(this.inputName).subscribe(data => {
this.result = data;
this.title = this.result.values.sections[0].foreground.title;
console.log(this.result.values.sections[0].foreground.title)
});
}
If this still produces error - please console log what you get in response above.
Here is working blitz:
https://stackblitz.com/edit/ionic-yuvxgm
I have small problem with my chat page :) wanted to do some chat application
I have login that is working but when I click to button chat it's crashing. I am beginner so maybe I can't see correctly. It's in Ionic 3
Home.ts
import { Component } from '#angular/core';
import { NavController, IonicPage } from 'ionic-angular';
import { Auth } from '#ionic/cloud-angular';
import { User } from '#ionic/cloud-angular';
import { LoginPage } from '../login/login';
import { About } from '../about/about';
import { ChatPage } from '../chat/chat';
#IonicPage()
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, public auth: Auth, public user: User) {
console.log(user);
}
logout() {
this.auth.logout();
this.navCtrl.setRoot(LoginPage);
}
about(){
this.navCtrl.setRoot(About);
this.navCtrl.push(About);
}
chat(){
this.navCtrl.setRoot(ChatPage);
this.navCtrl.push(ChatPage);
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>
Home
</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<h2>Welcome back, {{ user.details.name }}</h2>
<p>
<button ion-button color="secondary" block>Something</button>
</p>
<p>
<button ion-button color="secondary" block (click)="chatPage()">Chat</button>
</p>
<p>
<button ion-button color="secondary" block (click)="about()">About</button>
</p>
</ion-content>
chat.ts
import { Component, NgZone, ViewChild } from '#angular/core';
import { NavController, Content } from 'ionic-angular';
import { Validators, FormBuilder } from '#angular/forms';
import * as io from 'socket.io-client';
import { HomePage } from '../home/home';
#Component({
selector: 'page-chat',
templateUrl: 'chat.html'
})
export class ChatPage {
public chatForm: any;
#ViewChild(Content) content: Content;
messages:any = [];
socketHost: string = "http://localhost:3000/";
socket:any;
chat:any;
username:string;
zone:any;
chatField: any;
constructor(public navCtrl: NavController, private fb: FormBuilder){
this.socket = io.content(this.socketHost);
this.zone = new NgZone({enableLongStackTrace: false});
this.socket.on("chat me", (msg) =>{
this.zone.run (() =>{
this.messages.push(msg);
this.content.scrollToBottom();
});
});
this.chatForm = fb.group({
'chatField': ['', Validators.compose([Validators.required])],
});
this.chatField = this.chatForm.controls['chatField'];
}
chatSend(v) {
let data = {
message: v.chatText,
username: this.username
}
this.socket.emit('new message', data);
this.chat = "";
}
onSubmit(value: string): void {
if(this.chatForm.valid) {
}
}
}
chat.html
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Chat</ion-title>
</ion-navbar>
<ion-input [(ngModel)] = "username" placeholder="Username"> </ion-input>
</ion-header>
<ion-content class="chat">
<ion-list>
<div *ngFor="let data of messages">
<ion-item *ngIf="username === data.username" style="border-right: solid 5px red;">
<p class="chat-text" item-left>
<strong> {{data.username}}: </strong>
{{data.message}}
</p>
<p class="chat-time" item-right>
{{data.date | date:'dd/MM/yyyy'}}
</p>
</ion-item>
<ion-item *ngIf="username !== data.username" style="border-right: solid 5px green;">
<p class="chat-text" item-left>
<strong> {{data.username}}: </strong>
{{data.message}}
</p>
<p class="chat-time" item-right>
{{data.date | date:'dd/MM/yyyy'}}
</p>
</ion-item>
</div>
</ion-list>
</ion-content>
<ion-footer>
<form padding [formGroup]="chatForm" (ngSubmit)="onSubmit(chatForm.value)">
<ion-item>
<ion-input [(ngModel)]="chatField" name="chatText" required placeholder="type here....."></ion-input>
</ion-item>
<br/><br/>
<button type="submit" ion-button [disabled]="!chatForm.valid" block>Send</button>
</form>
</ion-footer>
the error that I am getting is
Runtime Error
co.chatPage is not a function
Stack
TypeError: co.chatPage is not a function
at Object.eval [as handleEvent] (ng:///AppModule/HomePage.ngfactory.js:290:24)
at handleEvent (http://localhost:8100/build/main.js:12302:138)
at callWithDebugContext (http://localhost:8100/build/main.js:13510:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:8100/build/main.js:13098:12)
at dispatchEvent (http://localhost:8100/build/main.js:9277:21)
at http://localhost:8100/build/main.js:9867:38
at HTMLButtonElement.<anonymous> (http://localhost:8100/build/main.js:35897:53)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12256)
at Object.onInvokeTask (http://localhost:8100/build/main.js:4613:37)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12177)
at n.runTask (http://localhost:8100/build/polyfills.js:3:7153)
at HTMLButtonElement.invoke (http://localhost:8100/build/polyfills.js:3:13213)
Ionic Framework: 3.1.1
Ionic App Scripts: 1.3.7
Angular Core: 4.0.2
Angular Compiler CLI: 4.0.2
Node: 7.2.0
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) App
The problem is you have called (click)="chatPage()" in your template and the function in your HomePage.ts is chat().
Do:
<button ion-button color="secondary" block (click)="chat()">Chat</button>
Side Note:
You dont have to do both push and setRoot.
setRoot will create an new navigation stack and set the particular page as Root.
push will push the page onto the current navigation stack.
Use one of them based on your requirement.
I am using a project to get some user data from Firebase. I want to put that data into a "Profile page". Everything works except for one problem. The data doesn't show on the html page until I click on an item in the page, like to edit some data for example. The data will also show if I click back, then reenter the page. So it's like the data loads the blank template, but never updates it once the data from Facebook is received. Any suggestions? Here is some of the code from the page.
profile.html
<ion-header>
<ion-navbar color="primary">
<ion-title>Profile</ion-title>
<ion-buttons end>
<button ion-button item-left icon-right (click)="logOut()">
<ion-icon name=""></ion-icon>
Logout
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-list-header>
Personal Information
</ion-list-header>
<ion-item (click)="updateName()">
<ion-grid>
<ion-row>
<ion-col width-50>
Name
</ion-col>
<ion-col *ngIf="userProfile?.firstName || userProfile?.lastName">
{{userProfile?.firstName}} {{userProfile?.lastName}}
</ion-col>
<ion-col class="placeholder-profile" *ngIf="!userProfile?.firstName">
<span>
Tap here to edit.
</span>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
<ion-item>
<ion-label class="dob-label">Date of Birth</ion-label>
<ion-datetime displayFormat="MMM D, YYYY" pickerFormat="D MMM YYYY"
[(ngModel)]="birthDate" (ionChange)="updateDOB(birthDate)"></ion-datetime>
</ion-item>
<ion-item (click)="updateEmail()">
<ion-grid>
<ion-row>
<ion-col width-50>
Email
</ion-col>
<ion-col width-50 *ngIf="userProfile?.email">
{{userProfile?.email}}
</ion-col>
<ion-col class="placeholder-profile" *ngIf="!userProfile?.email">
<span>
Tap here to edit.
</span>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
<ion-item (click)="updatePassword()">
<ion-grid>
<ion-row>
<ion-col width-50>
Password
</ion-col>
<ion-col class="placeholder-profile">
<span>
Tap here to edit.
</span>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-list>
</ion-content>
Here is the code from the profile.ts page
import { NavController, AlertController } from 'ionic-angular';
import { Component } from '#angular/core';
import { ProfileData } from '../../providers/profile-data';
import { AuthData } from '../../providers/auth-data';
import { LoginPage } from '../login/login';
#Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage {
public userProfile: any;
public birthDate: string;
zone: NgZone;
constructor(public navCtrl: NavController, public profileData: ProfileData,
public authData: AuthData, public alertCtrl: AlertController) {
}
ionViewDidEnter(){
this.profileData.getUserProfile().on('value', (data) => {
this.userProfile = data.val();
this.birthDate = this.userProfile.birthDate;
});
}
I also tried wrapping it in an NgZone object as suggested by others, which looks like this:
import { NavController, AlertController } from 'ionic-angular';
import { Component } from '#angular/core';
import { ProfileData } from '../../providers/profile-data';
import { AuthData } from '../../providers/auth-data';
import { LoginPage } from '../login/login';
import { NgZone } from '#angular/core';
#Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage {
public userProfile: any;
public birthDate: string;
zone: NgZone;
constructor(public navCtrl: NavController, public profileData: ProfileData,
public authData: AuthData, public alertCtrl: AlertController) {
this.zone = new NgZone({});
this.zone.run(() => {
//Your promise code
this.profileData.getUserProfile().on('value', (data) => {
this.userProfile = data.val();
this.birthDate = this.userProfile.birthDate;
});
});
}
None of this seems to work. The data is there, it just doesn't show until I click on an item/UI object, then it populates correctly. Help!
You have to do it like below.Hope code is self-explanatory.If you have any question, please comment below.
How to install Angularfire2?
ProfileData.ts
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
#Injectable()
export class ProfileData {
constructor(public af: AngularFire) {}
getUserProfile(data: string): FirebaseObjectObservable<any> {
return this.af.database.object(`path-to-your-firebase-object`);
}
}
YourComponent.ts
public profile: any;
constructor(public profileData: ProfileData) {
this.profileData.getUserProfile(your-user-id).subscribe(profileSnap => {
this.profile= profileSnap ;
});
}
import { Component } from '#angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {ModalPage} from '../modal-page/modal-page';
#Component({
selector: 'page-page2',
templateUrl: 'page2.html'
})
export class Page2 {
selectedItem: any;
icons: string[];
items: Array<{title: string, note: string, icon: string}>;
public nb:ModalPage;
constructor(public navCtrl: NavController, public navParams: NavParams) {
// If we navigated to this page, we will have an item available as a nav param
this.selectedItem = navParams.get('item');
// Let's populate this page with some filler content for funzies
this.icons = ['flask', 'wifi', 'beer', 'football', 'basketball', 'paper-plane',
'american-football', 'boat', 'bluetooth', 'build'];
this.items = [];
for (let i = 1; i < 11; i++) {
this.items.push({
title: 'Item ' + i,
note: 'This is item #' + i,
icon: this.icons[Math.floor(Math.random() * this.icons.length)]
});
}
}
itemTapped(event, item) {
// That's right, we're pushing to ourselves!
this.navCtrl.push(Page2, {
item: item
});
}
enablebuttonn(){
if ( this.nb.login()){
console.log("button va être activée");
}
}
}
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Page Two</ion-title>
<ion-buttons end>
<button ion-button icon-left>
<ion-icon name="paper"></ion-icon>
<span class="hide-xs">news</span>
</button>
<button ion-button #button1 disabled="true" icon-left (click)="enablebuttonn()">
<ion-icon name="car"></ion-icon>
<span class="hide-xs">voiture</span>
</button>
<button ion-button icon-left (click)="showAlert()">
<ion-icon name="chatbubbles"></ion-icon>
<span class="hide-xs">messages</span>
</button>
<button ion-button icon-only >
<ion-icon name="more"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">
<ion-icon [name]="item.icon" item-left></ion-icon>
{{item.title}}
<div class="item-note" item-right>
{{item.note}}
</div>
</button>
</ion-list>
<div *ngIf="selectedItem" padding>
You navigated here from <b>{{selectedItem.title}}</b>
</div>
</ion-content>
I'm working in a new mobile app with Ionic 2, and I'm trying to enable a button located in the ion-navbar while having success submitting from a modal page.
this a screenshot : voiture button ( in the top right ) is in the beginning disabled , i would like enable it while submitting.enter image description here
here is my page2 page ,ts file and the modal page
<button ion-button #button1 [disabled]="showButton" icon-left (click)="enablebuttonn()">
Notice the [] around the disabled attribute. This allows you to add logic to the attribute.
And then in the click event you can trigger the property to true
showbutton:boolean = false;
....
constructor(){
}
....
itemTapped(event, item) {
this.showbutton = true;
...
}