I am trying to call a function defined in the controller, but due to some silly mistake it does not call, here is my code. It should alert 1 defined in the getCustomerID function. The scope variables are set properly like this.title
HTML
<ons-template id="home.html">
<ons-page ng-controller="Home as page">
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="fn.open()">
<ons-icon icon="md-menu"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">
{{page.title}}
</div>
</ons-toolbar>
<p style="text-align: center; padding-top: 20px;">
Choose Client :
<select ng-model="filterCondition.operator" ng-change="getCustomerID()">
<option ng-repeat="x in customers" value="{{x.id}}">{{x.name}}</option>
</select>
<ons-button ng-click="page.getCustomerID()">Call</ons-button>
</p>
<div id="map"></div>
<br/>
<ons-button modifier="large" onclick="mylocation()">My Location</ons-button>
</ons-page>
</ons-template>
JS
app.controller('Home', function($scope){
$scope.page = {
title : "CRGroup",
name : localStorage.getItem("name"),
email : localStorage.getItem("email"),
profilepic : localStorage.getItem("profilepic"),
}
$scope.filterCondition={
operator: '1'
}
$.ajax({
type: 'GET',
url: 'http://XXXXX.php',
async: false,
data: {},
success: function (response) {
$scope.customers = response;
},
error: function (response) {
$scope.error = true;
$scope.$apply();
}
});
$scope.page.getCustomerID = function() {
alert(1);
}
});
controller asand$scopesyntax. You need to choose one or the other.controller assyntax a local variable forthiswill need to be created becausethis.inside the promise resolution will not refer to the controller.async:falseit's a bad practice.getCustomerIDfunction still does not call :(