0

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

My code is like this http://jsfiddle.net/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.

laser
  • 1,388
  • 13
  • 14
arnold
  • 1,682
  • 8
  • 24
  • 31
  • 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 Mar 03 '14 at 05:25

1 Answers1

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.org/guide/bootstrap

lucuma
  • 18,247
  • 4
  • 66
  • 91
  • what about the routing issue? can you explain it please? – arnold May 09 '13 at 13:34
  • @arnold, the plunkr in my answer shows the correct setup and works with the routing.. Click the add link. Also, here is a good link with regards to the html5Mode. http://stackoverflow.com/questions/13832529/how-to-config-routeprovider-and-locationprovider-in-angularjs Your fiddle was never going to work it had way too many issues with the basic setup. – lucuma May 09 '13 at 13:34
  • when I am clicking to "Add Me" its ok and going to "/new", but when I am trying to access directly using "mydomain.com/new" its returning 404, any idea? My htmlMode is on – arnold May 09 '13 at 14:53
  • 1
    mydomain.com/new won't work because your webserver is looking for a page with that name.. You either need to change the link to mydomain.com/#new OR you setup url redirects – lucuma May 09 '13 at 15:40
  • I meant to add your issue isn't an angular issue, it is a webserver issue in that /new for your webserver != / which in this case is where your single page app exists. – lucuma May 09 '13 at 15:46