如何首次设置angularjs app?

时间:2015-11-02 05:48:59

标签: html angularjs

我是angularjs的新手,并试图设置新的应用程序,但它总是给我错误角度没有定义,请让我知道什么是正确的方式来启动角应用程序。

的index.html

<!DOCTYPE html>
<html ng-app="app">
<head>
    <title>First App</title>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.min.css">
    <script type="text/javascript" src="bower_components/angular/angular.js"></script>
    <script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
</head>
<body>
      <div ui-view></div>
    <!-- We'll also add some navigation: -->

<script type="text/javascript" src="scripts/app.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>

</body>
</html>

main.html中

<div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

app.js

anuglar.module('app',['ngRoute']).config(function($stateProvider, $urlRouterProvider) {
  //
  // For any unmatched url, redirect to /state1
  $urlRouterProvider.otherwise("/");
  //
  // Now set up the states
  $stateProvider
    .state('state1', {
      url: "/state1",
      templateUrl: "views/main.html"
    })
});

1 个答案:

答案 0 :(得分:3)

你把

obb

低于<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>

你必须把它放在app.js

之前

喜欢这个

app.js

您使用了两次角度库文件

使用此

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<script type="text/javascript" src="scripts/app.js"></script>

或者

<script type="text/javascript" src="bower_components/angular/angular.js"></script>