I am currently working on an app using Cordova/Phonegap, Ionic, and AngularJS. One challenge I am facing is trying to call a method from a controller inside my app when redirecting to another HTML page (secondPage.html). This particular method (secondMethod()) performs a SQLite query to fetch some data which should then be displayed on the new page. Despite my attempts to use an onload function, I keep running into errors where the function cannot be found. How can I successfully accomplish this task?
app.js
ionicApp.controller("FirstController", function($scope) {
$scope.firstMethod = function() {
window.location.replace("secondPage.html");
}
}
ionicApp.controller("SecondController", function($scope) {
$scope.secondMethod = function() {
// Implement necessary code here
}
$scope.otherMethod = function() {
// Add other relevant code
}
}
secondPage.html
// Include necessary HTML and head elements
<body>
<ion-content ng-controller="SecondController">
<label id="text_label">Text</label>
<button class="button" ng-click="otherFunction()">Button</button>
</ion-content>
<script>
window.onload=secondMethod();
</script>
</body>
Any insights or guidance would be greatly appreciated.