Quantcast
Channel: Ionic Forum - Latest topics
Viewing all 70435 articles
Browse latest View live

Route doesnt work redirecting page to tab

$
0
0

@Abraham94 wrote:

Hi!
Im trying to navigate from a page to a tab with a button. The problem is that when I try to navigate from the tab to the page, it works, but not in the oposite way. what am I doing wrong?

app-routing.module.ts:


import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', 
  loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule)
  },
  {
    path: 'tabs',
 loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
  }
 



];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

tabs-routing.module.ts:


import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { TabsPage } from './tabs.page';


const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children:[
        { path: 'tab1', loadChildren: () => import('../tab1/tab1.module').then(m => m.Tab1PageModule) },
        { path: 'tab2', loadChildren: () => import('../tab2/tab2.module').then(m => m.Tab2PageModule) },
        
    ]
  },
  {
    path:'',
    redirectTo:'/tabs/tab1',
    pathMatch:'full'
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class TabsPageRoutingModule {}

method to navigate from page to tab:

import { Component, OnInit } from ‘@angular/core’;
import { Router } from ‘@angular/router’;

@Component({
selector: ‘app-login’,
templateUrl: ‘./login.page.html’,
styleUrls: [’./login.page.scss’],
})
export class LoginPage implements OnInit {

constructor(private router : Router) { }

ngOnInit() {
}

checkLogin(){
console.log(“HOLIII”)
console.log(this.router.navigate([‘tabs/tab1’]))
}

}

If u need more info , let me know.

Thanks! :slight_smile:

Posts: 1

Participants: 1

Read full topic


Wait for localstorage inside http observable?

$
0
0

@Yukko wrote:

Hey guys,
i’m fairly new to observables and i’m currently trying to change some code to understand the concept as a whole.
However, i came across a problem. I want to access my API using the http observable.

return this.http.get(BACKEND_URL + '/api/ROUTE', {
   headers: headers,
   params: params,
   observe: 'response'
}).pipe(map(response => {
   this.localStorage.setEtag(response.headers.get('etag'));
 }));

Before that, i want to add a header containing the last etag, which will get saved into local storage after fetching the data.
l

let headers = new HttpHeaders()
   .append('accept-language', localLanguage);
if (etag != null)
   headers = headers.append('If-None-Match', etag);

Now my problem lies within receiving the saved etag and waiting for it, since it is asynchonous.

let etag = '';
this.localStorage.getEtag()
   .then(data => {
      etag = data;
});

How can i wait for the local storage to complete in order to actually append it to the headers? The local storage returns as far as i know a promise of the value. For that reason i would like to (And had it prior to the observables) that i just await the etag and then append it into the headers. However, since this new method returns the observable i can’t await it since it would turn the return type to a promise.
I don’t know, if this whole approach is wrong at its core, i would appreciate some help.

Here is the full request method:

    public getInstances(): Observable<any> {
        let etag = '';
        this.localStorage.getEtagInstances()
            .then(data => {
                etag = data;
            });

        let headers = new HttpHeaders()
            .append('accept-language', localLanguage);
        if (etag != null)
            headers = headers.append('If-None-Match', etag);
        return this.http.get(BACKEND_URL + '/api/ROUTE', {
            headers: headers,
            params: params,
            observe: 'response'
        }).pipe(map(response => {
            this.localStorage.setEtagInstances(response.headers.get('etag'))
        }))
    }

Posts: 1

Participants: 1

Read full topic

Navigation is succesful but url doesn't get updated when on device

$
0
0

@curiousP wrote:

I am using angular routing and when I test it on the device, the navigation happens the way it should be, but the URL doesn’t get updated. So when I use router.url I am not getting the correct url.

Posts: 1

Participants: 1

Read full topic

Tab navigation with query parameters - impossible?

$
0
0

@doron wrote:

I am trying to navigate between tabs while passing some query parameters. I.e, when clicking on a tab button in the tab bar, I hope to pass some data via query parameters. This seems to be impossible to do right now, am I right?

More specifically, here is what I’m trying to do:

The first tab page I navigate to gets sent query parameters correctly, via router.navigate(url, {queryParams: { ...

Now, when clicking on another one of those tabs, I’d like to preserve the query parameters (inherit them from the first tab page, which had the query parameters in its URL so that the current tab page has the same parameters in its URL).

Great thanks to anybody who sheds light on this problem!

Posts: 1

Participants: 1

Read full topic

Is there a way to reopen the last opened directory to select a file and return the URI?

$
0
0

@leonardofmed wrote:

I’m using the Cordova FileChooser[1][2] and facing a small problem. On the most current Android devices, file selection always starts at root. Is there a way to open the file selection in a specific place on the device? Can I pass this parameter to this library? The only parameter I saw in the repository was to filter by file type.

If not, is there another way to do this, using this library or not?

Posts: 1

Participants: 1

Read full topic

Deprecation of injectCapacitor method

$
0
0

@mandolyte wrote:

There is currently a warning, followed by an error, when Electron is executed after the build:

WARNING: injectCapacitor method is deprecated and will be removed in next major release. Check release notes for mi
gration instructions

Trace
    at getURLFileContents (C:\Users\mando\Projects\cecil.new\r2\electron\node_modules\@capacitor\electron\index.js:
7:11)
    at injectCapacitor (C:\Users\mando\Projects\cecil.new\r2\electron\node_modules\@capacitor\electron\index.js:20:
33)
    at Timeout._onTimeout (C:\Users\mando\Projects\cecil.new\r2\electron\node_modules\@capacitor\electron\index.js:
156:44)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

After some debugging, I discovered that if I changed this line in ./electron/index.js from init(inject = true) to init(inject = false), then it works fine.

Then I found that this is the fix is already in place in the Github repo, but has not yet been released.

So two questions:

  • when will this fix be released to NPM?
  • any advice on a work-around in the meantime?

Posts: 1

Participants: 1

Read full topic

Having to call detectChanges() when using camera plugin

$
0
0

@Tanakasan1734 wrote:

I’ve that adding the ionic-native cordova camera plugin seemed to break change detection such that I had to call ChangeDetectorRef to get some bound data to change in the UI based on a Segment change- and not just in the component the plugin was added into others across different modules. I swapped it out for the Capacitor camera in Plugins, same problem. If I remove them the issue goes away. Any ideas on why? I have tried versions 1.5.1, 2.0.0 beta and released 2.0.0, same behaviour across all of them.

Posts: 1

Participants: 1

Read full topic

State Management In ReactJS Applications


How can I debug an Angular + Capacitor app in an android device?

$
0
0

@Pujy25 wrote:

Hi everyone!
I have an application created using Angular and Capacitor that stores some data in a SQLite database, so I can’t debug my application in a browser directly because I am using SQLite and that DB is not supported by the browser.

So, my problem is that I can’t find the way to debug my code directly on an Android device, right now I am using console.logs but to me it not makes sense, and I want to debug my code as usual (using debuggers and so on…) Is it possible?

After some research I got information about source-maps like this solution: https://github.com/ionic-team/ionic/issues/16455
but, it is not working… is there another solution? Has anyone had the same problem?

Thanks in advance!

Posts: 1

Participants: 1

Read full topic

Mailto doesnt work in InAppBrowser

$
0
0

@edbusquets wrote:

If I try to open a link with mailto in InAppBrowser it doesnt launch the mail application and closes the InAppBrowser tab.

<a href="mailto:someone@domain.com"> some text</a>

Instead the same link with mailto in the application if it works and opens the email application.

Version: @ionic-native/in-app-browser 5.22.0

Has anyone made it work? ty

Posts: 1

Participants: 1

Read full topic

Production build failing on iOS

$
0
0

@tofra wrote:

Currently i’m kinda lost, tried several things, but I still get this error, and I can’t find any clue on where to look.

I’m doing a production build (ionic cordova prepare ios --prod --release) which successfully builds. But upon running it on iOS (using Xcode on the simulator, or directly on an iPhone) the splashscreen shows with the “spinner”, and there it stays. In the log window of Xcode/Safari I do see that several other data of the application is loaded/processed, so under the splash screen the app is building up the screen with what to show.

ERROR: Unhandled Promise rejection: undefined is not an object (near '...,t),t[i]),E)})(r,e)).then&&(o=await o),o...') ; Zone: <root> ; Task: Promise.then ; Value: TypeError: undefined is not an object (near '...,t),t[i]),E)})(r,e)).then&&(o=await o),o...') ionic://localhost/main-latest.a5adcb5b80b4647a2721.js:1:687411
asyncFunctionResume@[native code]
value@ionic://localhost/polyfills-latest.9367b0957c85ca80c13b.js:1:5388
ionic://localhost/polyfills-latest.9367b0957c85ca80c13b.js:1:18355
value@ionic://localhost/polyfills-latest.9367b0957c85ca80c13b.js:1:6180
m@ionic://localhost/polyfills-latest.9367b0957c85ca80c13b.js:1:14336
promiseReactionJob@[native code]

Another weird thing is, that is sometimes helps if I delete the node_modules directory, then do an npm install and then do the build… Sometimes…

Any clue where I should start looking?

Posts: 1

Participants: 1

Read full topic

Help! Try to install does not work! Mac Catalina

$
0
0

@fgarcia73 wrote:

owner@Owners-MacBook-Air ~ % npm install -g @ionic/cli

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

npm ERR! code EACCES

npm ERR! syscall access

npm ERR! path /usr/local/lib/node_modules

npm ERR! errno -13

npm ERR! Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’

npm ERR! [Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’] {

npm ERR! stack: “Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’”,

npm ERR! errno: -13,

npm ERR! code: ‘EACCES’,

npm ERR! syscall: ‘access’,

npm ERR! path: ‘/usr/local/lib/node_modules’

npm ERR! }

npm ERR!

npm ERR! The operation was rejected by your operating system.

npm ERR! It is likely you do not have the permissions to access this file as the current user

npm ERR!

npm ERR! If you believe this might be a permissions issue, please double-check the

npm ERR! permissions of the file and its containing directories, or try running

npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:

npm ERR! /Users/owner/.npm/_logs/2020-04-07T16_30_17_907Z-debug.log

owner@Owners-MacBook-Air ~ %

Posts: 1

Participants: 1

Read full topic

Handle alert action when keyboard enter key is hit

$
0
0

@shepard wrote:

If I create an alert, how can I handle the Save button when the keyboard ‘Go’ button is pressed?

this.alertCtrl.create({
            header: 'YourAddress',
            message: 'What is your address?",
            inputs: [
                {
                    name: 'address',
                    type: 'text',
                    value: this.address,
                    placeholder: 'Address'
                }
            ],
            buttons: [
                {
                    text: 'Cancel',
                    handler: data => {
                        console.log('Cancel clicked');
                    }
                },
                {
                    text: 'Save',
                    handler: data => {
                        console.log('SAVE DATA: ' + data);
                    }
                }
            ]
        }).then(alert => alert.present());
@HostListener('document:keydown.enter', ['$event']) onKeydownHandler(evt: KeyboardEvent) {
        console.log('enter key hit: How do I handle the alert as if the Save button was pressed? ');
    }

Posts: 1

Participants: 1

Read full topic

Background image does not show if added dynamically

$
0
0

@erkinalan wrote:

I am building an App with ionic 5 where the user should be allowed to customize the background image.

My code:

.html file:

<ion-content  [ngStyle]="{'background-image':'url('+ backgroundImage + ')'}"></ion-content>

.ts file

        this.backgroundImage = '../../assets/image/backgroundImage.png';

Posts: 4

Participants: 2

Read full topic

How to add a share this app buton to my ionic app

$
0
0

@Galilo wrote:

I am new to the ionic framework.
I am using ionic with angular. I need to add a button to allow users to share the app on social media (facebook, email, whatsapp …)
I am using firebase for backend (maybe I need dynamic links).
Do anyone have a full and complete sample or tutorial?
Otherwise, pls direct me.

Posts: 2

Participants: 2

Read full topic


Problem whenever npm install is executed in Ionic 3

$
0
0

@guatemala wrote:

Hi everyone,

I’m trying to update an Ionic 3 app from version 3.8.0 to 3.9.9 and I was following the guide on the GitHub repository (https://github.com/ionic-team/ionic-v3/blob/fa7b53608b57adb22bf9d2d4fed2b6a615220f1e/CHANGELOG.md#390-2017-11-08)

I updated the dependencies as specified in the guide but now I’m getting an error when I execute “npm install”

This is my ionic info:

cli packages: (/Users/yoyofcbmx/.nvm/versions/node/v6.10.3/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0

local packages:

@ionic/app-scripts : 3.2.4
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.9.9

System:

ios-sim : 8.0.2
Node    : v6.10.3
npm     : 3.10.10
OS      : macOS
Xcode   : Xcode 11.4 Build version 11E146

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

And this is the error I’m getting whenever I execute the “npm install” command

npm WARN deprecated @angular/http@5.2.11: Package no longer supported. Use @angular/common instead, see https://angular.io/guide/deprecations#angularhttp
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated rollup-plugin-commonjs@8.2.6: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-commonjs.
npm WARN deprecated rollup-plugin-node-resolve@3.0.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-node-resolve.
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN prefer global node-gyp@3.8.0 should be installed with -g
npm WARN prefer global ios-sim@8.0.2 should be installed with -g

fsevents@1.2.12 install /Users/yoyofcbmx/Code/guatemala_appgt/node_modules/fsevents
node-gyp rebuild

SOLINK_MODULE(target) Release/.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
ld: library not found for -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/yoyofcbmx/.nvm/versions/node/v6.10.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 19.4.0
gyp ERR! command “/Users/yoyofcbmx/.nvm/versions/node/v6.10.3/bin/node” “/Users/yoyofcbmx/.nvm/versions/node/v6.10.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild”
gyp ERR! cwd /Users/yoyofcbmx/Code/guatemala_appgt/node_modules/fsevents
gyp ERR! node -v v6.10.3
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

Posts: 1

Participants: 1

Read full topic

How can I programmatically add a prior state using angular ui router/ionicframework

$
0
0

@nasaner-il wrote:

ionicframework v1.3.0

After successful login, my users user see a landing page. Sometimes I want to have my user jump to a special page after login instead of the landing page, but still be able to navigate back to the landing page with a back button.
If I use $state.go('/special-page') , then the user will not see the link for the back/home button in the ion-nav-bar. How can I do this? Could I programmatically add a prior state?

Posts: 1

Participants: 1

Read full topic

How to navigate to a route that requires a parameter when none exists?

$
0
0

@Sweg wrote:

I am trying to create an Ionic 5 / Angular app that provides the following functionality to users:

  • Display a List of Mechanics on Mechanic-List page
  • A user can click on a mechanic so they can then send a message to the mechanic

Below is the structure I’m trying to implement, please let me know if it doesn’t make sense, or if there’s a better way:

Display list of mechanics in Mechanic-List below:

<ion-list>
    <ion-item *ngFor="let mechanic of loadedMechanics" (click)="onMechanicClick(mechanic.id)">
        <h2>{{ mechanic.name }}</h2>
    </ion-item>
</ion-list>

Here is how I am populating Mechanic-List:

Mechanic-list.page.ts:

this.loadedMechanics = this.usersService.getAllMechanics();

Users.service.ts:

private _users: User[] = [
    new User('user1', 'John', 'mechanic'),
    new User('user2', 'Phil', 'mechanic'),
    new User('user3', 'Andrew', 'customer'),
  ];

getAllMechanics() {
    return this.users.filter(user => user.userType === 'mechanic');
  }

Then when the user clicks on a Mechanic, open an ActionController by executing the below code:

onMechanicClick(mechanicId: string) {
    this.actionSheetCtrl.create({
      buttons: [
        {
          text: 'Send Message',
          handler: () => {
            this.goToConversationDetail(mechanicId);
          }
        }
      ]
    }).then(actionSheetEl => {
      actionSheetEl.present();
    });
  }

Then when the user clicks the Send Message button, navigate to the Conversation-Detail page.

This is where I am getting stuck.

Here is the current path for the Conversation-Detail page:

path: 'conversation-detail/:conversationId',

So you have to have an existing conversationId.

This works fine for existing conversations, I just pass the conversationId in using the below structure:

private _conversations: Conversation[] = [
    new Conversation(
      'conversation1',
      'user3',
      'user1',
      [
        new Message('message1', 'Test message', 'user3', '01/01/2020'),
        new Message('message2', 'Another message', 'user1', '02/01/2020')
      ]),
    new Conversation(
      'conversation2',
      'user4',
      'user2',
      [
        new Message('message3', 'my  message', 'user4', '05/03/2020'),
        new Message('message4', 'more messages', 'user2', '08/03/2020')
      ])
  ];

But I want to know whats the best way to start off a new conversation between a Mechanic & a User.

In other words when there is no existing Conversation, what is the best way to begin one? Do I need to have a different page?

Any advice would be greatly appreciated, thanks a lot!

Posts: 1

Participants: 1

Read full topic

Can't import Cordova Zip plugin

$
0
0

@leonardofmed wrote:

After installing the Zip plugin

ionic cordova plugin add cordova-plugin-zip
npm install @ionic-native/zip

and importing in app.module.ts

import { Zip } from '@ionic-native/zip/ngx';

I got the following error:

ERROR in ./src/app/app.module.ts
[ng] Module not found: Error: Can’t resolve ‘@ionic-native/zip/ngx’

If I try to import as ‘@ionic-native/zip’:

Uncaught TypeError: Object(…) is not a function

Am I missing something?

Posts: 1

Participants: 1

Read full topic

Ionic 5 Get Request to Slim API

$
0
0

@KTSB wrote:

0

I would like to make a get request from my Ionic app to an API build with the Slim Framework.

This is the code of the API:

<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
?>
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Tuupola\Middleware\HttpBasicAuthentication;

require 'vendor/autoload.php';
$jwt_secret = '**************';

$app = new Slim\App;

$app->add(new Tuupola\Middleware\JwtAuthentication([
    "path" => "/api",
    "attribute" => "jwt",
    "secret" => $jwt_secret,  "error" => function ($response, $arguments) {
        $data["status"] = "error";
        $data["message"] = $arguments["message"];
        return $response
            ->withHeader("Content-Type", "application/json")
            ->withHeader("Access-Control-Allow-Origin", "*")
            ->getBody()->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
    }
]));

$app->get('/api/hello', function (Request $request, Response $response, array $args) 
{
    $decoded = $request->getAttribute("jwt");
    $response->getBody()->write(json_encode(array("status"=> "200", "message" => "HELLO ".$decoded['uid'] ." - " . $decoded['cus'])));

    return $response;
});

$app->get('/', function (Request $request, Response $response, array $args) {
    $response->getBody()->write(json_encode(array("status"=> "200", "message" => "Welcome to the API")));

    return $response;
});

$app->run();

?>

When I’m testing with postman the API works fine. But when I’m trying to call it with the HTTPClient in Ionic, it doesn’t work. This is my Ionic Code:

import { Component } from '@angular/core';
import { HttpClient, HttpHeaders   } from '@angular/common/http';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})

export class HomePage {

  constructor(private http: HttpClient) 
  {

  }

  sendRequest()
  {
    this.http.get('http://localhost/slim3',).subscribe((data)=>console.log(data));
  }

}

The Error message is the following: :8100/home:1 Access to XMLHttpRequest at ‘http://localhost/slim3’ from origin ‘http://localhost:8100’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

core.js:6014 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: “Unknown Error”, url: “http://localhost/slim3”, ok: false, …}

How can I fix it? Thanks!

Posts: 1

Participants: 1

Read full topic

Viewing all 70435 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>