加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular JS路由不起作用,只显示部分路径,而不是部

发布时间:2020-12-17 06:52:34 所属栏目:安全 来源:网络整理
导读:我正在关注AngularJS – “Building a website with AngularJS”的教程 我使用的路线与教程几乎相同: // JavaScript Documentangular.module('quest',[]). config(function($routeProvider) { $routeProvider. when('/about',{template:'partials/about.htm
我正在关注AngularJS – “Building a website with AngularJS”的教程

我使用的路线与教程几乎相同:

// JavaScript Document
angular.module('quest',[]).
    config(function($routeProvider) {
        $routeProvider.
            when('/about',{template:'partials/about.html'}).
            when('/start',{template:'partials/start.html'}).
            otherwise({redirectTo:'/home',template:'partials/home.html'});
    });

问题是:它只显示资源的路径,而不是资源的内容,因此它不显示html内容,而是显示:

PARTIALS/ABOUT.HTML

我不确定我做错了什么,但它确实有效,如果我转到#/ about URL它显示“PARTIALS / ABOUT.HTML”如果我将url更改为index.html#/ start它显示“PARTIALS /的start.html”

页面的HTML:

<!DOCTYPE html>
<html lang="en" ng-app="quest">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width,height=device-height,target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title></title>
    </head>
    <body ng-controller="MainController">
        <script type="text/javascript" src="js/angular.min.js"></script>
        <script type="text/javascript" src="js/quest.js"></script>

        <div ng-view></div>

    </body>
</html>

解决方法

使用templateUrl而不是模板

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读