简体   繁体   English

express + angular,如何使用templateURL

[英]express+angular, how to use templateURL

The project is based on Express, and no view-engine is used. 该项目基于Express,不使用任何视图引擎。 I set some static directories: 我设置了一些静态目录:

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

index.js is in webroot, directoris is like: index.js位于webroot中,directoris类似于:

/
/index.js
/public
/view
/view/index.html(index)
/view/sidebar.html
/public/js/app.js(js for index.html)

The index.html include scripts is like: index.html包含脚本类似于:

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

The directive in index.html is: index.html中的指令为:

<my-sidebar></my-sidebar>

app.js: app.js:

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

The templateURL doesn't work well, how can I write it, or how can I see the URL in my bower. templateURL不正常,如何编写它,或者如何在Bower中看到URL。 Tx! TX!

Thank u for watching my problem. 感谢您收看我的问题。 I finally found that my chrome didn't work well and the code I provided is correct. 我终于发现我的chrome无法正常运行,并且我提供的代码是正确的。 Here I provide another way which require a view engine: 在这里,我提供了另一种需要视图引擎的方式:

npm install --save ejs    

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

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

The templateURL send a 'GET' http request so that I can write app.get('/sidebar.html') to receive to request and render the html. templateURL发送一个“ GET” http请求,这样我就可以编写app.get('/sidebar.html')来接收请求并呈现html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM