小编Mic*_*thi的帖子

如何解决 AngularJs 路由不起作用的问题

我正在编写一些简单的代码来练习角度路由。我有一个 index.html 文件,其中包含用于访问相应模板的链接和用于显示模板的 div 元素。然而,当单击链接时,模板不会显示,并且 URL 也不会按预期显示。

url 显示为: http://localhost/angproj/#!#%2Fhome 而不是预期的http://localhost/angproj#/home

这是代码:

索引.html

<!DOCTYPE html>
<html ng-app = "myModule">
<head>
    <title>Home</title>
    <link rel="stylesheet" href ="styles.css">
    <script src="angular/angular.min.js"></script>
    <script src="angular-route.min.js"></script>
    <script src="script.js"></script>
    <meta name="vieport" content="width=device-width initial scale=1">
</head>
<body>
    <header><h2>Website Header</h2></header>
        <div class="column">
            <div class="links">
            <a href="#/home">Home</a><br>
            <a href="#/services">Our services</a><br>
            <a href="#/technologies">Technologies</a><br>
        </div>
        </div>
        <div class="content" ng-view></div>
    <footer><h3>Website footer</h3></footer>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

脚本文件

var myApp = angular
            .module("myModule",["ngRoute"])
            .config(function($routeProvider){
                $routeProvider
                .when("/home",{
                    template:"About Us"
                })
                .when("/services",{
                    template:"Our Services"
                })
                .when("/technologies",{
                  template:"Our Technologies" …
Run Code Online (Sandbox Code Playgroud)

html javascript angularjs angularjs-routing

1
推荐指数
1
解决办法
5350
查看次数

标签 统计

angularjs ×1

angularjs-routing ×1

html ×1

javascript ×1