Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all 49252 articles
Browse latest View live

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

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

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

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 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

How to create a smooth transition when moving from modal to another page in Ionic 5 app?

$
0
0

@Sweg wrote:

In my Ionic 5 / Angular app, I am trying to navigate from a Modal to another page in the app.

I’m able to navigate & close the modal, but the transition isn’t smooth.

I don’t know how to explain it exactly, but it just doesn’t look right.

Here is the button on my modal:

<ion-button color="primary" (click)="onSendMessage()">Send Message</ion-button>

onSendMessage() {
    this.modalCtrl.dismiss(null, 'cancel'); //
    this.router.navigateByUrl('conversation-list'); // need to smoothen out this transition
  }

As I said, this works "functionality-wise", but is there a way to make the smooth transition?

Thanks a lot!

Posts: 1

Participants: 1

Read full topic


Add platform android : Failed because of upload images error

$
0
0

@ravikab wrote:

Iam using ionic 3 and every time when i execute ionic cordova platform add android I get the below pasted error. Iam using Azure pipeline to build the android apk

Is the server down? How can it be solved? It was working few days back and there is no problem with images

ionic cordova resources android --force
:heavy_check_mark: Collecting resource configuration and source images - done!
:heavy_check_mark: Filtering out image resources that do not need regeneration - done!
:heavy_multiplication_x: Uploading source images to prepare for transformations - failed!
HTTP Error 503: POST https://res.ionic.io/api/v1/upload

cordova@8.1.2
ionic@3.20.0
cordova-android@~7.1.1

Posts: 2

Participants: 2

Read full topic

HTTP iOS url string

$
0
0

@basti wrote:

Hi, I try to deal with the native HTTP and pass some data via get to a server. On android it works without any problem.
On iOS there is unfortunately this error:

***** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:], /Users/.../Plugins/cordova-plugin-advanced-http/AFURLRequestSerialization.m:347**

A search brought that the problem should be in the provided url, but on Android the same url is no problem.
Here is a demo-url which crashes:

http://demo.com/app-set.php?id=GOZFGHET&klasse=3&stunde=112&uebungen=[{"title":"Hampelmann","uebung":"","saetze":3,"wiederholungen":10,"done":false}]&wow_id=QVTOPGLD

Could there be something with this url?

Posts: 1

Participants: 1

Read full topic

Want to download youtube video?

$
0
0

@convertmp3 wrote:

if you want to convert your favorite youtube video to mp3 and download easily its free tool and safe website you can visit website convertmp3 its convert your tube video easily.

convert mp3 video

convert mp3 for youtube

convert mp3 youtube

youtube mp3 converter online

youtube to mp3 cc

youtube mp3 free

youtube convert mp3

i suggest same tool Ytmp3Conv its free and safe.

youtube mp3 online

youtube to mp3 hd

youtube mp3 music

Posts: 1

Participants: 1

Read full topic

Streaming videos are not playing in IOS

$
0
0

@VigneshBalakrishnan wrote:

Hi all,
I have using the html5 video tag to stream media files from aws. IOS devices are not playing videos, even mp4 files are not playing. Could any one please help me to solve this issue, thanks.

Posts: 1

Participants: 1

Read full topic

Ngrx in Ionic 5

$
0
0

@zornic wrote:

I have few concerns when using ngrx in mobile app with Ionic 5:

  1. Performance issues on mobile devices. = ngrx is state management so all data from API will be stored in memory and accessible all the time. Could this effect some older devices(e.g. android 4.4)?

  2. Too much ngrx boilerplate can increase app bundle size.

  3. Can’t use ngrx/data due to a lot of limitations

  4. ngrx is 3rd party library. Is it 100% compatible with Ionic Angular?

Is there anyone out there who has faced the similar issues?

Posts: 1

Participants: 1

Read full topic

Viewing all 49252 articles
Browse latest View live


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