Timon Timon - 5 months ago 35
AngularJS Question

Ionic android button not working

Im facing a problem with my ionic app. I coded the whole app over the webbrowser through ionic serve. Now I want to publish my app on an android device.

In the web everything works fine but when I try to start the app on my android 4.3 or 5.5 device nothing happens when i click the login button on the login page.

this is my login template:

<ion-view view-title="Anmelden" name="login-view">
<ion-content class="padding">
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Username" ng-model="data.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Passwort" ng-model="data.password">
</label>
</div>
<button class="button button-block button-positive" ng-click="login(data)">Login</button>
</ion-content>
</ion-view>


my routing (simplified), it's in my app.js after the run function:

.config(function ($stateProvider, $urlRouterProvider, USER_ROLES) {
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
$urlRouterProvider.otherwise('/login');
})


The actual function in my LoginCtrl is not getting called, so I assume that my template somehow has no connection to it's routing.
The button just appears dead and nothing happens when you press it (also monitored incoming http requests on my webserver).

I also tried to change from ng-click to on-tap.
Can somebody help me? Thanks a lot.

Regards

Answer

Add this to your header in index.html (refer http://content-security-policy.com/)

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

And you should add cordova-plugin-whitelist to your project (refer https://github.com/apache/cordova-plugin-whitelist)

cordova plugin add cordova-plugin-whitelist

And add the following lines to your config.xml

<access origin="*" />
<allow-intent href="*" />
Comments