0

i want to make route with angularjs. but when i run my app, ng-view doesnt show anything. i'm new in angularjs.

index :

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CRUD</title>
</head>
<body ng-App="myAPP">
  <a href='#/'/>List</a>
  <a href='#/addData'/>Add Data</a>

  <div>
    <div ng-view></div>
  </div>

  <script src="js/angular.js"></script>
  <script src="js/angular-route.js"></script>
  <script src="js/app.js"></script>
  <script src="controller/controller.js"></script>
</body>
</html>

app.js :

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

route.js :

app.config(['$routeProvider',function($routeProvider){
    $routeProvider.when('/',{
        templateURL : 'crud/pages/list.html',
        controller : 'controller'
    })
    .when('/addData',{
        templateURL : 'crud/pages/coba.html',
        controller : 'controller'
    })
    .otherwise({
        redirectTo : '/'
    })
}])
3
  • I have already given one answer, Please refer this : stackoverflow.com/questions/40038399/… Commented Oct 18, 2016 at 4:22
  • your default route(/) loads list.html page. show your list.html page Commented Oct 18, 2016 at 4:35
  • have u declared controllers or not? Commented Oct 18, 2016 at 6:08

4 Answers 4

1

You have not closed the js/angular-route.js tag

  <script src="js/angular.js"></script>
  <script src="js/angular-route.js"></script>
  <script src="js/app.js"></script>

DEMO

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

1 Comment

just fix the templateURL, it will work, and yes the script tag is missing the trailing slash. that should be corrected for this to work.
0

You have written templateURL instead of written templateUrl. Other than that everything is fine.

And Please close the brackets <script></script>

templateURL --> templateUrl

5 Comments

i've close the brackets and change templateURL to templateUrl but it's still cant show
did you define the controller function and are the templates paths correct and file present? This works - plnkr.co/edit/RjXujNvD6hCTPudRwYIW?p=preview
Please check this link: DEMO
Its better you use angular-ui-router rather than angular-router. Angular UI-router has lot of components than angular-router. Please revisit the link: DEMO
Check this one, same as your demo : DEMO
0

You should probably add all your script tag inside your head tag that would make it work and close the script tag too.

Comments

0

check here for source code, cool to understand

https://github.com/umakantmane/single-page-app

Comments

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.