0

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:

Error image

Thank you for your time.

1 Answer 1

1

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: "/"
              });

});
Sign up to request clarification or add additional context in comments.

1 Comment

@U R It's still not working. But i am confused because my other url (/detilsoal/:nomor/:id) is working. I also check the network on my broswer and it does load nilai.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.