Alert function not working (iOS)

ios

#1

I can’t seem to get the alert function to work. I’ve tried:

// 1.
alert('hello');

// 2.
import * as dialogs from 'ui/dialogs';
alert('hello');

// 3.
import * as dialogs from 'tns-core-modules/ui/dialogs'; // Shouldn't be needed at all.
alert('hello');

I’ve read:
https://docs.nativescript.org/ui/ns-ui-widgets/dialogs
and
https://docs.nativescript.org/ui/dialogs

But I can’t get it working following that. Any idea what is happening? Why it’s not working at all?

I’m on iOS. And using Nativescript + Angular.


#2

It should work.

Are you getting any errors?
Are you able to reproduce the issue with Playground?


#3

I’m not getting any errors. But the code is definitely executed since I have a console.log there too. I’ve tried a full rebuild too, deleted the ios folder after every combination of importing and not importing ../ui/dialogs.

Didn’t try it in the playground.

The only slightly “bigger” change I’ve made to the angular template I started from was replace page-router-outlet with router-outlet to allow child routes in named router-outlets. But That shouldn’t have an impact on that I would assume.


#4

This is my bootstrapped file now, as simple as I can think of and it’s still not working:

import { Component, OnInit } from "@angular/core";

@Component({
  selector: "my-app",
  template: `
    <StackLayout>
      <Label text="Hi"></Label>
    </StackLayout>
  `
})
export class AppComponent implements OnInit {  
  ngOnInit() {
    alert('I will not show up!');
  }
}

Also tried to put the alert in a setTimeout but nope.


#5

Smells like this issue: https://github.com/NativeScript/NativeScript/pull/6000

You could try with the @next version of tns-core-modules.


#6

How about, I happened the same, I solved it by deleting the folders node_modules, hooks, platforms, then with a tns install verifies if all the folders that you deleted were generated and there is a tns run android or ios


#7

I ended up using fancy-alert. Didn’t work for me with deleting node_modules and platform folder. Maybe if I tried deleting hooks also but now I’m just using this instead.


#8

As Eddy mentioned you need at least one frame for alert to work, but it should be fixed in next release.