Quantcast
Channel: Ionic Forum - Latest posts
Viewing all 228527 articles
Browse latest View live

Updating list upon ionic storage set() completion

$
0
0

Length is cool, especially when the post is as well-written and well-formatted as this one is. You are under absolutely no compulsion to take my opinion as anything other than the opinion of a really opinionated opinion-haver, and more than likely somebody else will be along shortly to offer a different one.

That being said, I recognize in your code several things that I used to do when I was starting out writing webapps, and no longer do any more for various reasons. I can expand more on why if desired, but:

I spent a lot of time writing C++, and putting as much “intelligence” into data-bearing objects is pretty idiomatic for OOP code. JavaScript is not an OO language. It pretends to be one, but you will be happier in the long run if you refuse to believe it. I now completely swear off “smart” data-bearing objects in JavaScript in favor of TypeScript interfaces (which are just POJOs), and choose to put all the “smarts” in wranglers. One major reason is because we get to avoid all of this error-prone tedium:

.pipe(
      map((customers) => {
        return customers ? JSON.parse(customers).map(
          (customer: Customer) => new Customer(customer)) : []
      })
    )

We no longer have to worry about sprinkling magic Customer constructor pixie dust on things, a problem our toolchain unfortunately can’t help us avoid because JavaScript.

So I would convert Customer to an interface and put whatever intelligence is currently in it into CustomersService instead.

This looks like a neat feature, but one showstopper problem with it is that you can’t override it elsewhere. This makes mocking it out for testing virtually impossible. So I don’t use it, instead just declaring services in the provider stanza of my app module.

Now we get to the main event:

Never use Storage to communicate within runs of an app. Use it only to talk to the future and listen to the past.

Your situation here is precisely why I adopted this rule. Yes, it’s possible to implement the design you’ve chosen by judiciously waiting off the Promise returned by storage.set. However, as you’ve discovered, it’s a PITA to do. It also introduces a needless performance bottleneck. So what I would do instead is this:

import {clone} from "lodash-es";
export class CustomersService {
  private customers$ = new BehaviorSubject<Customer[]>([]);
  constructor(private storage: Storage) {
    // this is the only time we read from storage:
    // once at app startup to listen to the past
    storage.ready()
      .then(() => storage.get(StorageConstants.customers))
      .then((customers) => {
        if (customers) { this.customers$.next(customers); }
      });
  }
  getCustomers(): Observable<Customer[]> {
    return this.customers$;
  }
  addCustomer(customer: Customer): void {
    // this clone may be avoided in some circumstances, but exists because
    // it's not easy to detect changes to deep object references in JavaScript
    let newCustomers = clone(this.customers$.value);
    newCustomers.push(customer);
    // the in-app communication is done entirely within CustomersService
    this.customers$.next(newCustomers);
    // here we speak to the future, and don't care when it's ready to be heard
    this.storage.set(StorageConstants.customers, newCustomers);
  }
}

Interactive Debug with VSCode and Android Emulator

Ionic 4 ngOnDestroy not called from component on page navigation

$
0
0

if you prefer to use the Angular way, adding { replaceUrl: true } as NavigationExtra:

this.router.navigate([page.url], { replaceUrl: true });

or on template

<a [routerLink]="page.url" replaceUrl="true">...

Ionic cordova build android not creating apk file

$
0
0

did you try reinstalling node modules and plugin

I cannot install cordova-res

Help in sending Get Request in Ionic

$
0
0

Thanks for the reminders. However, I have already dealt with my situation but it doesn’t have anything to do with Https nor SSL certificate. I’m grateful regardless!

Ionic cordova build android not creating apk file

$
0
0

Yes, I reinstalled the node modules & plugin, Android platform

Ion-Virtual-Scroll render problem

$
0
0

I have a problem with ion-virtual-scroll. Sometimes its render my items correctly, but sometimes my items stack like in this photo

How i can fix it or any trick to prevent that ?


Travel Bundle - Ionic 3 ionBooking and tripIonic Themes

Why my navigate is not working

$
0
0

When I change app-routing.module.ts’s

loadChildren: () => import('./login/login.module').then( m => m.LoginPageModule)
to
component: LoginPage

It works. But I don’t know why.

Ion-select-option unable to give any event

$
0
0

I want to implement select all functionality for . this is what i did

<ion-select multiple=“true” [(ngModel)]=“day” name=“day” (select)=“selectAll(myselect)” required >

  <ion-select-option  value="selectall" (onSelect)="SelectAll()"> select all</ion-select-option>

   

  <ion-select-option value="Monday">Monday</ion-select-option>

   <ion-select-option value="Tuesday">Tuesday</ion-select-option>

   <ion-select-option value="Wednesday">Wednesday</ion-select-option>

   <ion-select-option value="Thursday">Thursday </ion-select-option>

   <ion-select-option value="Friday">Friday </ion-select-option>

   <ion-select-option value="Saturday">Saturday</ion-select-option>

   <ion-select-option value="Sunday">Sunday </ion-select-option>

 </ion-select>

I am not able to give any event on . I checked the response at console and nothing was reflected there.
Instead of (onSelect): - (onChange), (change), (select) was tried.

Scss file is not working

routerLink not updating url value when changed

$
0
0

Hello,
Thank you for your reply. Yes the segment is generated outside of appPages

The problem does not come from the generation of the segment, but from the component “App Component” which is loaded only once in the application and does not update the information when it changes.

Here are code snippets.

// settings.effects.ts
@Injectable()
export class SettingsEffects {
    ...

    constructor(
        private actions$: Actions,
        private store: Store<State>,
        private segmentRouterService: SegmentRouterService,
    ) {
    }

    initSegment$ = createEffect(() =>
            this.actions$.pipe(
                ofType(ROOT_EFFECTS_INIT),
                switchMap(() => {
                    return this.segmentRouterService.init();
                }),
                tap((segment: string) => {
                    if (segment) {
                        this.store.dispatch(SettingsActions.init({settings: {segment}}));
                    }
                })
            ),
        {dispatch: false}
    );

    ...
}
// settings.facade.ts
@Injectable()
export class SettingsFacade {
    ...

    private readonly segment$ = this.store.pipe(select(SettingsSelector.selectSegment));

    constructor(private store: Store<State>) {
    }

    changeSegment(segment: string): void {
        this.store.dispatch(SettingsActions.changeSegment({segment}));
    }

    get segment(): Observable<any> {
        return this.segment$;
    }

    ...
}
// segment-router.service.ts
@Injectable({
    providedIn: 'root'
})
export class SegmentRouterService implements OnDestroy {
    private value: string;
    private currentValue: string;
    private defaultValue = 'adults';

    subscription$ = new Subject<any>();
    routerEvents = new Subject<string>();

    constructor(
        private router: Router,
        private settingsFacade: SettingsFacade,
    ) {
        this.routerEvents
            .pipe(takeUntil(this.subscription$))
            .subscribe(async (segment: string) => {
                this.buildSegment(segment);
            });
    }

    async init(): Promise<any> {
        return new Promise((resolve) => {
            this.router.events
                .pipe(
                    filter((event: RouterEvent) => event instanceof ResolveStart),
                    map((event: ResolveStart) => {
                        let data = null;
                        let route = event.state.root;

                        while (route) {
                            data = route.data || data;
                            route = route.firstChild;
                        }

                        return data.segment;
                    }),
                    distinctUntilChanged(),
                    takeUntil(this.subscription$),
                )
                .subscribe((segment: string) => {
                    this.routerEvents.next(segment);
                    this.onSegmentChangeEmitter.emit(segment);

                    resolve(this.currentSegment);
                });
        });
    }

    ngOnDestroy(): void {
        this.subscription$.next();
        this.subscription$.complete();
    }

    private buildSegment(segment: string) {
        this.value = segment;

        if (segment === this.defaultValue || segment === 'none') {
            this.currentValue = '';
        } else {
            this.currentValue = segment;
        }

        this.settingsFacade.changeSegment(this.currentValue);
    }
}

Send data from one component to other

$
0
0

can I send socket object by using @Input and @output , so please show with example, because I was tried ,It was not showing.

Angular HTTP Client

$
0
0

Your code is perfectly fine. I’m just not sure whether to pin the cause of your problem on your network.


Cannot read property 'length' of undefined -v

$
0
0

Although this problem happened everywhere not for this project.
that means & is not a concern.
I think the problem with the environment but everything is updated…

Angular HTTP Client

$
0
0

Try to use a different http endpoint in the outside world from one of the many tutorials (spotify, google, esrthquake data weather etc)

Just a dummy http request to isolate what is working and isnt

I get error when i use social-sharing on ionic3

$
0
0

I got a run time error when click the facebook btn for share …

this.socialSharing.shareViaFacebook(“text”, null, null).then(() => {

  console.log("shareViaFacebook: Success");

}).catch(() => {

  console.error("shareViaFacebook: failed");

}); 

And also other social share.

ionic-error-2

My IONIC info as

Ionic:

Ionic CLI : 5.4.2 (C:\apps\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.5
@ionic/app-scripts : 3.2.4

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 7 other plugins)

Utility:

cordova-res : 0.8.1
native-run : 0.3.0

System:

NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.13.1
OS : Windows 10


Installed plugins are

ionic-error-3

Problem social-sharing ionic v 3

$
0
0

I got the same problem but not fixing the problem. Any one can help me if possible

ionic-error-2

My IONIC info as

Ionic:

Ionic CLI : 5.4.2 (C:\apps\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.5
@ionic/app-scripts : 3.2.4

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 7 other plugins)

Utility:

cordova-res : 0.8.1
native-run : 0.3.0

System:

NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.13.1
OS : Windows 10

Installed plugins are

ionic-error-3

How to use capacitor-udp plugin

$
0
0

Crazy, i can not get it working. I just created a new capacitor project and used your code.
I installed the plugin and added android platform and run it it simulator:

vendor-es2015.js:44320 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'create' of undefined TypeError: Cannot read property 'create' of undefined at Tab1Page.<anonymous> (tab1-tab1-module-es2015.js:2852) at Generator.next (<anonymous>) at vendor-es2015.js:119189 at new ZoneAwarePromise (polyfills-es2015.js:3882) at Module.__awaiter (vendor-es2015.js:119185) at Tab1Page.process (tab1-tab1-module-es2015.js:2850) at Object.eval [as handleEvent] (Tab1Page.html:10) at handleEvent (vendor-es2015.js:73308) at callWithDebugContext (vendor-es2015.js:74926) at Object.debugHandleEvent [as handleEvent] (vendor-es2015.js:74562) at resolvePromise (polyfills-es2015.js:3803) at new ZoneAwarePromise (polyfills-es2015.js:3885) at Module.__awaiter (vendor-es2015.js:119185) at Tab1Page.process (tab1-tab1-module-es2015.js:2850) at Object.eval [as handleEvent] (Tab1Page.html:10) at handleEvent (vendor-es2015.js:73308) at callWithDebugContext (vendor-es2015.js:74926) at Object.debugHandleEvent [as handleEvent] (vendor-es2015.js:74562) at dispatchEvent (vendor-es2015.js:61028) at vendor-es2015.js:72240

Viewing all 228527 articles
Browse latest View live


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