简单的指令不适用于Cloud9?

时间:2014-11-18 10:11:50

标签: angularjs cloud9-ide

我似乎无法在cloud9中重做一个简单的指令教程。基本上它不会产生输出"在这里我要保存一天"。

main2.js

var app = angular.module("superhero", []);

app.directive("superman", function() {
return {
    restrict: "E",
    template: "<div>Here I am to save the day</div>"
}
})

此功能在此处加载到索引文件中,如下所示。另外我还有一个名为main.js的文件,我在其中声明了应用程序&#34; myApp&#34;,但即使删除它也无济于事。

的index.html

<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My AngularJS App</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css">
  <link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css">
  <link rel="stylesheet" href="app.css">
  <script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>


  <div ng-app="superhero">
    <superman></superman>
  </div>


  <!-- In production use:
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
  -->
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="app.js"></script>
  <script src="main.js"></script>
  <script src="main2.js"></script>
  <script src="view1/view1.js"></script>
  <script src="view2/view2.js"></script>
  <script src="components/version/version.js"></script>
  <script src="components/version/version-directive.js"></script>
  <script src="components/version/interpolate-filter.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要在

之前加载main2.js脚本(和角度文件)
<div ng-app="superhero">
    <superman></superman>
</div>

我在jsfiddle.net中尝试过,只有当javascript在HTML之前加载到页面的头部时才会起作用。