0

I have a an angular single page app that loads correctly on for the home and about pages. But the edit route goes into an infinite loop of errors.

The error is

SyntaxError: Unexpected token '<'

I call editCaldera() using a button in a table using ng-click

<table class="table">
  <thead>
    <tr>
      <th scope="col">id</th>
      <th scope="col">Borrower1</th>
      <th scope="col">Email</th>
      <th scope="col">Address</th>
      <th scope="col">ContactNumber</th>
      <th scope="col">Lender</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="caldera in calderas">
      <td>{{ caldera._id }}</td>
      <td>{{ caldera.Borrower1 }}</td>
      <td>{{ caldera.Email }}</td>
      <td>{{ caldera.Address }}</td>
      <td>{{ caldera.ContactNumber }}</td>
      <td>{{ caldera.Lender }}</td>
      <td><button ng-click="editCaldera(caldera._id)">Edit</button></td>
      <td><button ng-click="deleteCaldera(caldera._id)">Delete</button></td>
    </tr>
  </tbody>
</table>

Below is my main javascript file.

var calderaApp = angular.module('calderaApp', ['ngRoute']);

calderaApp.config(function($locationProvider, $routeProvider) {
  $locationProvider.html5Mode(true);

  $routeProvider

    // route for the home page
    .when('/', {
      templateUrl: 'pages/home.html',
      controller: 'mainController'
    })

    // route for the about page
    .when('/about', {
      templateUrl: 'pages/about.html',
      controller: 'aboutController'
    })
    .when('/edit/:id', {
      templateUrl: 'pages/edit.html',
      controller: 'editController'
    })
});



calderaApp.controller('mainController', function($scope, $http, $location) {

  // when landing on the page, get all todos and show them
  $http.get('/findall')
    .success(function(data) {
      console.log(data);
      $scope.calderas = data;

    })
    .error(function(data) {
      console.log('Error: ' + data);
    });

  // when submitting the add form, send the text to the node API
  $scope.editCaldera = function(id) {
    console.log('editCaldera function')
    var earl = '/edit/' + id;
    $location.url(earl);
  };
});

calderaApp.controller('aboutController', function($scope, $http) {
  $scope.message = 'Look! I am an about page.';
});

calderaApp.controller('editController', function($scope, $http, $routeParams) {
  console.log('edit')
});

I need the id field to then make an API call but even before making this call and just with a very basic controller a loop occurs.

7
  • What do you see in the network tab (developer tools) when the edit view load from the server? Commented Oct 23, 2018 at 13:46
  • you are using html5Mode, did you change your server-side routing manually? The issue is probably there Commented Oct 23, 2018 at 13:47
  • removing the html5mode seems to have solved the issue, why is this? Commented Oct 23, 2018 at 13:49
  • angularjs routing relies on a hash-bang (/#!/), which you removed with html5mode (to make your URL pretty). So to fix your routing, you need to change it on server-side manually as well Commented Oct 23, 2018 at 13:51
  • how do i remove this hash bang now i have html5mode turned off Commented Oct 23, 2018 at 14:03

0

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.