如何结合angularjs和xhtml? [英] How to combine angularjs and xhtml?

查看:93
本文介绍了如何结合angularjs和xhtml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是angularjs的最小示例的一个示例,当另存为angular.html时可以正常工作:

Here is an example of a minimal example for angularjs which works when saved as angular.html:

<!DOCTYPE html>
<html lang="en" xmlns:ng="http://angularjs.org" ng:app="">
<head>
  <title>My HTML File</title>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
</head>
<body>

  <p>Nothing here {{'yet' + '!'}}</p>

</body>
</html>

但是,我坚信XML,并且我希望创建所有符合XML的html文档.我尝试修改该示例并将其另存为angular.xhtml:

However I strongly believe in XML and I like to create all my html documents XML compliant. I tried to adapt the example and save it as angular.xhtml:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:ng="http://angularjs.org" ng:app="">
<head>
  <title>My HTML File</title>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js" />
</head>
<body>

  <p>Nothing here {{'yet' + '!'}}</p>

</body>
</html>

最大的变化是xhtml-Namespace和文件扩展名".xhtml".没有错误或任何东西.只是页面显示得好像没有角度一样.

The big changes are the xhtml-Namespace and the file extension ".xhtml". There is no error or anything. It's just that the page is displayed as if angular was not present.

如何让angularjs处理XML兼容文件?

How do I get angularjs working with an XML compliant file?

推荐答案

我找到了使用手动设置的解决方案.然后,代码如下所示:

I found a solution using manual setup. The code then looks like this:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>My HTML File</title>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js" />
    <script type="text/javascript">
        angular.module('myApp', []);

    angular.element(document).ready(function() {
      angular.bootstrap(document, ['myApp']);
    });
  </script>
</head>
<body>

  <p>Nothing here {{'yet' + '!'}}</p>

</body>
</html>

虽然目前看来这是一个合适的解决方法,但我仍然很想知道问题出在哪里...

While this seems a suitable workaround for now, I'd still love to know what the problem is...

这篇关于如何结合angularjs和xhtml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆