Reputation: 27
Good day everybody, i want to ask a little question about angularjs ngview. I just learned about angular a week ago.
In my code, my web show infinite loop of the index itself, instead if showing the right page. I already search on stackoverflow for the same problem, but still cannot fix my problem.
Here's my app.js code:
app.config(function($routeProvider, $locationProvider)
{
$routeProvider.when("/detilsoal/:nomor/:id",
{
templateUrl: "/detil_soal.html"
controller: "soalLengkap"
}).when("/nilai/:id",
{
templateUrl: "/nilai.html",
controller: "hitungNilai"
}).otherwise(
{
redirectTo: "/"
});
});
Here's my controller (i just want to check if the controller is used correctly):
app.controller('hitungNilai', function($scope, $http, $routeParams)
{
console.log('error');
});
And here's my nilai.html view (located in public/nilai.html) :
<div class="row" id="head_soal">
<div id="kotak_dalam" ng-controller="hitungNilai">
<h2>JUMLAH NILAI</h2>
<div class="row" id="isi soal" style="padding: 3%;margin-left: 1%;">
</div>
</div>
</div>
And here's the picture when i go to address:
Thank you for your time.
Upvotes: 0
Views: 308
Reputation: 2148
the problem is you are redirectiong to /
but you didn't initialize
.when("/",
{
templateUrl: "/detil_soal.html"
controller: "soalLengkap"
})
use this code...
app.config(function($routeProvider, $locationProvider)
{
$routeProvider.when("/",
{
templateUrl: "/detil_soal.html"
controller: "soalLengkap"
}).when("/detilsoal/:nomor/:id",
{
templateUrl: "/detil_soal.html"
controller: "soalLengkap"
}).when("/nilai/:id",
{
templateUrl: "/nilai.html",
controller: "hitungNilai"
}).otherwise(
{
redirectTo: "/"
});
});
Upvotes: 1