简体   繁体   中英

Angular UI Router: Cannot log inside of .config

I've been trying to link up components of a simple Angular app but cannot seem to get my initial view state to load. One main issue seems to be that I can't even log inside of my .config setup (despite making sure that everything is syntactically correct). As far as I can tell (after some testing) all of my files are in the right locations).

Anybody see any glaring mistakes?

index.html:

<!DOCTYPE html>
<html>
  <head></head>
    <title>Thing</title>

  <body class="container">

    <div class="row">
      <div class="span12">
        <div class="well" ui-view></div>
      </div>
    </div>

    <!-- dependencies -->
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.min.js"></script>
    <script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
    <!-- css files -->

    <!-- application files -->
    <script src="js/app.js"></script>
    <script src="js/payments.js"></script>

    <!-- Google Maps -->
     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
  </body>

</html>

app.js:

var paymentApp = angular.module('paymentApp', ['ui.router'])

.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/payments')
  // Now set up the states
  console.log("in config")

  $stateProvider
    .state('payments', {
      url: "/payments",
      templateUrl: "view/payments.html"
    })

});

payments.html:

<h1>Payments Page</h1>
<div class="buttons">
  <button>Click Me!</button>
</div>

<div class="search"></div>

<div class="payments"></div>

Quite a simple mistake to make - you have forgotten to bootstrap your angular app.

You need to add the ng-app directive somewhere and point it to your module.

Eg

<html ng-app="paymentApp">

https://docs.angularjs.org/api/ng/directive/ngApp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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