我使用Cordova / Phonegap,Ionic和AngularJS构建应用程序。我想从外部执行一个来自控制器的内部方法。当我重定向到另一个html(secondPage.html)时,应该执行这个内部方法(secondMethod())。我的方法运行SQLite查询,以获取一些数据,并应在新页面上显示它。我尝试使用onload-function,但我的console.log说,它无法找到我的功能。我怎么能这样做?
app.js
ionicApp.controller("FirstController", function($scope) {
$scope.firstMethod = function() {
window.location.replace("secondPage.html");
}
}
ionicApp.controller("SecondController", function($scope) {
$scope.secondMethod = function() {
// do some code
}
$scope.otherMethod = function() {
// some other code
}
}
secondPage.html
// html and head
<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>
提前谢谢。