Fidha Nasher Fidha Nasher - 3 months ago 9
AngularJS Question

angularjs App not loading in cordova when open a page through anchor tage

I am created a Cordova app with angularjs.Angular perfectly worked in index.html page;But Angular not loaded when open another page with angular App.

my Page is given below:

<!DOCTYPE html>
<html ng-app="myApp">
<head>

</head>
<body ng-controller="onlineresultController">
<div id="deviceready" class="body padding">
<br>
<br>
<br>
<div ng-show="publish">
<form ng-show="hideResult" name="email-form" data-name="Email Form" action="javascript:void(0);" ng-submit="getResult();">
<div>
<label class="label-form" for="address2-field">Enter Roll Number</label>
<input class="w-input input-form" id="address2-field" type="text" name="hallticketno" data-name="address2" ng-model="hallticketno" placeholder="Roll Number" required="">
<div class="separator-fields"></div>
</div>

<div align="center">
<button type="submit" class="button">Get Result</button>
<div class="separator-fields"></div>
</div>
</form>
</div>
<div ng-hide="hideResult" class="row">
<div id="printDiv" class="row col-sm-8">
<table class="blue table table-responsive">
<tbody>
<tr>
<td class="text-center" colspan="2"><h5><b>Name: <span style="color:blue;" >{{result.student.name}}</span> <|-|> Roll No: <span style="color:blue;">{{result.student.hallticketno}}</span></b></h5></td>
</tr>
<tr align="center">
<td><h4><b>Mark</b></h4></td><td><h4><b>Rank</b></h4></td>
</tr>
<tr align="center">
<td><h4 class="text-primary">{{result.mark}}</h4></td><td><h4 class="text-primary">{{result.rank}}</h4></td>
</tr>
</tbody>
</table>
</div>
<div id="editor"></div>
</div>
<div ng-hide="hideResult" class="box text-center">
<a ng-click="checkAnother();">Check Another Result</a><button id="print" class="btn btn-primary text-center">Print</button>
</div>
<div ng-hide="publish" class="row">
<div align="center">
<h1>Result not Published</h1>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/angular-route.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/framework.js"></script>
<script type="text/javascript">
app.initialize();
angular.element(document).ready(function () {

angular.bootstrap(document, ["myApp"]);

});

</script>
<script type="text/javascript">

var myApp = angular.module("myApp", []);
myApp.controller("onlineresultController", [ '$scope','$http', function($scope,$http) {
$scope.result = [];
$scope.publish=false;
$scope.errors={};
$scope.showerror=false;
$scope.hallticketno='';
$scope.hideResult=true;

$http.get('http://192.168.10.137:8000/getsettings/').
success(function (data, status, headers, config) {
if(data[0].result=='1')
$scope.publish=true;
else
$scope.publish=false;

console.log(data);
}).error(function (data, status, headers, config) {
console.log(data);
});

$scope.checkAnother=function(){
$scope.result = [];
$scope.publish=true;
$scope.errors={};
$scope.showerror=false;
$scope.hallticketno='';
$scope.hideResult=true;
}

$scope.getResult=function(){
$http.get('http://192.168.10.137:8000/getresult',{params:{hallticketno:$scope.hallticketno}}).
success(function (data, status, headers, config) {
$scope.result=data;
$scope.errors={};
$scope.showerror=false;
$scope.hideResult=false;
console.log(data);
}).error(function (data, status, headers, config) {
$scope.errors=data;
$scope.showerror=true;
console.log(data);
});
}

} ]);



</script>
</body>
</html>


I need you help to know how to load angularjs app when loading page through anchor tag.
It working fine in browsers but on mobile it not working.

Answer

Gives onclick instead of href in 'a' tage of html like this

  <a onclick="callCentrePage()>Home Page</a>

The create a javascript function to load that page

 function callCentrePage()
 {
    window.location = "centers.html";
 }

After doing it AngularJs works all page by opening through menu.I hope you understand it.

Comments