ng-view不显示在angularjs中

时间:2022-08-15 19:41:06

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

我想用angularjs制作路线。但是当我运行我的应用程序时,ng-view没有显示任何内容。我是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 : '/'
    })
}])

4 个解决方案

#1


1  

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

您尚未关闭js / angular-route.js标记

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

DEMO

#2


0  

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

您编写了templateURL而不是编写的templateUrl。除此之外一切都很好。

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

并请关闭括号

templateURL --> templateUrl

templateURL - > templateUrl

#3


0  

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

您应该在头标记中添加所有脚本标记,以使其工作并关闭脚本标记。

#4


0  

check here for source code, cool to understand

在这里查看源代码,很酷才能理解

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

#1


1  

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

您尚未关闭js / angular-route.js标记

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

DEMO

#2


0  

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

您编写了templateURL而不是编写的templateUrl。除此之外一切都很好。

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

并请关闭括号

templateURL --> templateUrl

templateURL - > templateUrl

#3


0  

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

您应该在头标记中添加所有脚本标记,以使其工作并关闭脚本标记。

#4


0  

check here for source code, cool to understand

在这里查看源代码,很酷才能理解

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