javascript - AngularJS routing configuration -
i new angularjs, trying build crud app it.
my code http://jsfiddle.net/fpnna/1/
and using apache webserver, when turing on
$locationprovider.html5mode(true);
then getting
uncaught typeerror: object #<ic> has no method 'html5mode' testapp
when clicking "add new" path changing "/new" getting error
404 requested url /new not found on server.
any idea doing wrong.
i went through official manual, couldn't figure out.
thanks in advance.
you have couple issues, first in jsfiddle don't need body tags plus have multiple body tags. fiddle has 2 ng-apps, routes defined incorrectly (should /new instance), invalid ng-view closing tag, there should one. should include javascript no wrap in head , lastly html5mode
capital m
on mode , none of partials exist @ urls nor defined local scripts.
i suggest use plunkr allows add other local files, ie partials don't exist in fiddle.
i've cleaned of issues on plunkr: http://plnkr.co/edit/a23fxn9ji02tgz0jouzr?p=preview
angular.module('testapp', []). config(function ($routeprovider, $locationprovider) { $locationprovider.html5mode(true); // case important $routeprovider. when("/", { templateurl: "list.html" }). when("/new", { // make sure , use absolute link route templateurl: "edit.html" }) }) function testctrl($scope) { $scope.persons = [{ name: "x" }, { name: "y" }, { name: "z" }] }
and 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 documentation , tutorials learn basics on setting project. http://docs.angularjs.org/guide/bootstrap
Comments
Post a Comment