开始使用角度辅助

时间:2016-02-02 23:37:03

标签: javascript angularjs

我正在尝试输出Hello World,但我得到的只是{{“Hello World”}}。这是我第一次使用角度应用程序。谁能告诉我我的代码中缺少什么?我导入了angular.min.js,我在app.js中声明了应用程序并将其附加到html标签,但我仍然无法输出hello world。有什么想法吗?

<!DOCTYPE html>
<html ng-app="app">
  <head>
    <title>Bootstrap 3</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script type="text/javascript" src="angular.min.js"></script>
            <script type="text/javascript" src="app.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <link href="index.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="css/reset.css">
  </head>

  <body ng-controller="bodyController">
    <div class="navbar navbar-inverse navbar-static-top">
      <div class="container">
        <div class="navbar-header">
          <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a href="#" class="navbar-brand">Tech Site</a>
        </div>
        <div class="collapse navbar-collapse navHeaderCollapse">
          <ul class="nav navbar-nav">
            <li><a href="#">Specs and Features</a></li>
            <li><a href="#">How To Videos</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Social Media <b class = "caret"></b></a>
              <ul class="dropdown-menu ">
                <li><a href="#">Twitter</a></li>
                <li><a href="#">Facebook</a></li>
                <li><a href="#">Google+</a></li>
                <li><a href="#">Instagram</a></li>
              </ul>
            </li>
            <li></li>
          </ul>
        </div>
      </div>
    </div>

    <div class="container">      
      <div class="row">
        <div class="col-md-2 " ></div>
        <div class="col-md-8 " >
          {{"Hello World"}}     
        </div> 
        <div class="col-md-2 " ></div>  
      </div>
    </div>

    <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
  </body>
</html>

app.js

(function() {

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

    app.controller("BodyController", function(){
        this.foods = fruits;
        });


     var fruits = [
    { name: 'Apples', calories: 65, totalFat: '0g', Saturated Fat: '0g' Cholestrol 0mg, sodium: '1mg', totalCarbs: '17g', dietaryFiber: '3g', Sugar: '13g', Protein: '0g', vitaminA: '1%', vitaminC: 10%, Calcium: 1%, Iron: 1%},
    { name: 'Oranges', price: 5.95 },
    { name: 'Pineapple', price: 3.95 }
  ];
})();

1 个答案:

答案 0 :(得分:0)

你的app.controllers名称(bodyController不同)和你的水果列表中有一些语法错误。你需要更加谨慎地使用语法

通过这些改变你可以看到你的hello world


(function() {

    var app = angular.module('app', []);
    app.controller("bodyController", function(){
        this.foods = fruits;
        });
    var fruits = [
        { name: 'Apples', calories: 65, totalFat: '0g', Saturated_Fat: '0g', Cholestrol: '0mg', 
          sodium: '1mg', totalCarbs: '17g', dietaryFiber: '3g', Sugar: '13g', 
          Protein: '0g', vitaminA: '1%', vitaminC: '10%', Calcium: '1%', Iron: '1%'
        },
        { name: 'Oranges', price: 5.95 },
        { name: 'Pineapple', price: 3.95 }
    ];
    })();