angular.js - express+angular,使用templateURL的路径问题
淡淡烟草味
淡淡烟草味 2017-05-15 17:12:24
0
3
672

使用express构建的服务,没有使用视图引擎,将项目目录设置为静态:

app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/view'));
app.use(express.static(__dirname + '/node_modules'));

node入口文件index.js在根目录下,目录结构为:

/
/index.js
/public
/view
/view/index.html(首页)
/view/sidebar.html(侧边菜单)
/public/js/app.js(首页的js文件)

index.html中引入如下:

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

index.html指令如下:

<my-sidebar></my-sidebar>

app.js如下:

var app = angular.module("myBlog", ["ngRoute"]);
app.directive("mySidebar", function () {
    return  {
        restrict: "E",
        replace: true,
        templateURL: "sidebar.html",
    }
})

经过测试发现templateURL没有起作用,请问应该如何写这个路径,或者如何查看这里的templateURL到底被解析成了什么样子?

淡淡烟草味
淡淡烟草味

reply all(3)
仅有的幸福

It has been solved. There is something wrong with my chrome. The original code is written correctly.
Provides a way to use the ejs view engine:

app.engine('html', require('ejs').__express);
app.set('view engine', 'html');

app.get('/sidebar.html', function (req, res) {
   res.render('sidebar.html');
})
阿神

../../view/sidebar.html

滿天的星座

Write templateURL as an absolute path templateURL: '/view/sidebar.html'

Or add the root path of the component html template in the <base> tag

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!