admin管理员组

文章数量:1023187

I am new to angularjs, was just trying to build a CRUD app with it.

My code is like this /

And I am using apache as webserver, when turing on the

$locationProvider.html5mode(true);

then getting

uncaught TypeError: Object #<Ic> has no method 'html5mode' from testApp 

When I am clicking to "Add new" the path changing to "/new" but getting error

404 The requested URL /new was not found on this server.

Any idea where I am doing wrong.

I went through the official manual, couldn't figure it out.

Thanks in advance.

I am new to angularjs, was just trying to build a CRUD app with it.

My code is like this http://jsfiddle/fpnna/1/

And I am using apache as webserver, when turing on the

$locationProvider.html5mode(true);

then getting

uncaught TypeError: Object #<Ic> has no method 'html5mode' from testApp 

When I am clicking to "Add new" the path changing to "/new" but getting error

404 The requested URL /new was not found on this server.

Any idea where I am doing wrong.

I went through the official manual, couldn't figure it out.

Thanks in advance.

Share Improve this question edited Jun 20, 2017 at 7:25 laser 1,37613 silver badges14 bronze badges asked May 9, 2013 at 12:55 arnoldarnold 1,7129 gold badges25 silver badges31 bronze badges 1
  • 2 I hate it when someone gets downvotes for a case typo. We've all done it, and many of us have went ahead and thrown it up here and been shamed. However, the fact that the OP put the error and question out there means others who are working into a 20+ hour sprint and can't type or think straight anymore get to easily cross this bug off of their list. Thank you OP. You probably saved me 20 minutes when it really matters the most. – Brian Vanderbusch Commented Mar 3, 2014 at 5:25
Add a ment  | 

1 Answer 1

Reset to default 5

You have a couple issues, first in jsfiddle you don't need the body tags plus you have multiple body tags. Also your fiddle has two ng-apps, the routes are defined incorrectly (should be /new for instance), invalid ng-view closing tag, there should only be one. You should include the javascript with No wrap in head and lastly it is html5Mode with a capital M on the mode and none of your partials exist at their urls nor are they defined as local scripts.

I would suggest you use plunkr as it allows you to add other local files, ie your partials which don't exist in the fiddle.

I've cleaned up all of the issues on this plunkr: http://plnkr.co/edit/A23Fxn9Ji02TGZ0jouZR?p=preview

angular.module('testApp', []).
config(function ($routeProvider, $locationProvider) {
     $locationProvider.html5Mode(true);  // case is important
    $routeProvider.
    when("/", {
        templateUrl: "list.html"
    }).
    when("/new", {  // make sure and use absolute link to route
        templateUrl: "edit.html"
    })
})

function testCtrl($scope) {
    $scope.persons = [{
        name: "X"
    }, {
        name: "Y"
    }, {
        name: "Z"
    }]
}

and the html:

<body ng-controller="testCtrl" >
  <div class="main-nav">  <a href="new">Add Me</a>
    </div>INDEX
    <div  >
        <div ng-view>

        </div>
    </div>
</body>

Please review the documentation and tutorials to learn the basics on setting up a project. http://docs.angularjs/guide/bootstrap

I am new to angularjs, was just trying to build a CRUD app with it.

My code is like this /

And I am using apache as webserver, when turing on the

$locationProvider.html5mode(true);

then getting

uncaught TypeError: Object #<Ic> has no method 'html5mode' from testApp 

When I am clicking to "Add new" the path changing to "/new" but getting error

404 The requested URL /new was not found on this server.

Any idea where I am doing wrong.

I went through the official manual, couldn't figure it out.

Thanks in advance.

I am new to angularjs, was just trying to build a CRUD app with it.

My code is like this http://jsfiddle/fpnna/1/

And I am using apache as webserver, when turing on the

$locationProvider.html5mode(true);

then getting

uncaught TypeError: Object #<Ic> has no method 'html5mode' from testApp 

When I am clicking to "Add new" the path changing to "/new" but getting error

404 The requested URL /new was not found on this server.

Any idea where I am doing wrong.

I went through the official manual, couldn't figure it out.

Thanks in advance.

Share Improve this question edited Jun 20, 2017 at 7:25 laser 1,37613 silver badges14 bronze badges asked May 9, 2013 at 12:55 arnoldarnold 1,7129 gold badges25 silver badges31 bronze badges 1
  • 2 I hate it when someone gets downvotes for a case typo. We've all done it, and many of us have went ahead and thrown it up here and been shamed. However, the fact that the OP put the error and question out there means others who are working into a 20+ hour sprint and can't type or think straight anymore get to easily cross this bug off of their list. Thank you OP. You probably saved me 20 minutes when it really matters the most. – Brian Vanderbusch Commented Mar 3, 2014 at 5:25
Add a ment  | 

1 Answer 1

Reset to default 5

You have a couple issues, first in jsfiddle you don't need the body tags plus you have multiple body tags. Also your fiddle has two ng-apps, the routes are defined incorrectly (should be /new for instance), invalid ng-view closing tag, there should only be one. You should include the javascript with No wrap in head and lastly it is html5Mode with a capital M on the mode and none of your partials exist at their urls nor are they defined as local scripts.

I would suggest you use plunkr as it allows you to add other local files, ie your partials which don't exist in the fiddle.

I've cleaned up all of the issues on this plunkr: http://plnkr.co/edit/A23Fxn9Ji02TGZ0jouZR?p=preview

angular.module('testApp', []).
config(function ($routeProvider, $locationProvider) {
     $locationProvider.html5Mode(true);  // case is important
    $routeProvider.
    when("/", {
        templateUrl: "list.html"
    }).
    when("/new", {  // make sure and use absolute link to route
        templateUrl: "edit.html"
    })
})

function testCtrl($scope) {
    $scope.persons = [{
        name: "X"
    }, {
        name: "Y"
    }, {
        name: "Z"
    }]
}

and the html:

<body ng-controller="testCtrl" >
  <div class="main-nav">  <a href="new">Add Me</a>
    </div>INDEX
    <div  >
        <div ng-view>

        </div>
    </div>
</body>

Please review the documentation and tutorials to learn the basics on setting up a project. http://docs.angularjs/guide/bootstrap

本文标签: javascriptAngularJS routing configurationStack Overflow