简体   繁体   English

AngularJS Hello World不起作用

[英]AngularJS Hello World does not work

I'm getting started with AngularJS and surprisingly this super simple piece of code is not working. 我开始使用AngularJS,令人惊讶的是这段超级简单的代码无效。 This page is served by expressJS with the hogan render engine. 该页面由expressJS和hogan渲染引擎提供。

The console doesn't say anything and my file paths are all correct and double checked. 控制台没有说什么,我的文件路径都是正确的并且双重检查。 Still this simple data-binding does not work. 这种简单的数据绑定仍然不起作用。 Please help. 请帮忙。

<!doctype html>
<html lang="en" >
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/angular.min.js"></script>
    <script src="../js/angular-route.min.js"></script>
    <script src="../js/angular-cookies.min.js"></script>
    <script src="../js/angular-resource.min.js"></script>
    <script src="../js/angular-animate.min.js"></script>
</head>
<body>

    <div ng-app>
        <input type="text" ng-model="unm">
        <h2>Hello {{unm}}</h2>
    </div>


</body>
</html>

Problem solved. 问题解决了。 As I mentioned, I'm using the Hogan render engine in Express which has the same template brackets {{ }} as AngularJS. 正如我所提到的,我在Express中使用Hogan渲染引擎,它与AngularJS具有相同的模板括号{{}}。 Hence when the page is rendered, Hogan strips all {{ }} thereby virtually removing the {{unm}}. 因此,当呈现页面时,Hogan会删除所有{{}},从而虚拟删除{{unm}}。

I've solved this problem by adding this line to my ExpressJS app : 我通过将此行添加到ExpressJS应用程序中解决了这个问题:

app.locals.delimiters = '{{{ }}}';

Now, Hogan variables can be put inside {{{somevariable}}} while Angular works with its usual {{unm}}. 现在,Hogan变量可以放在{{{somevariable}}}中,而Angular可以使用其通常的{{unm}}。 They no longer conflict now. 他们现在不再发生冲突。

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

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