如何在angularjs的控制器中获取变量

时间:2018-08-25 02:13:21

标签: angularjs

我的控制器:

<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

<div id=header>
    <img src="http://www.free-icons-download.net/images/lightning-bolt-logo-icon-76715.png" alt="Lightning" id="header-img">
  <h1>Lightning-Fast Muay Thai Gloves</h1>
<nav id="nav-bar">
<a href="#glove" class="nav-link">Why this glove?</a>
<a href="#features" class="nav-link">Features</a>
<a href="#pricing" class="nav-link">Pricing</a>
  </nav>
</div>

  <div id="glove">
  <div id="leather" class="glove-feature">
    <img src="https://png.icons8.com/ios/1600/leather-filled.png" alt="leather" id="leather-img">
  <div class="description">
    <h2>Authentic Leather</h2>
  <p>Leather that won't crack and endure even the harshest blows. Straight from Phuket province.</p> 
    </div>
</div>
    <div id="science" class="glove-feature">
<img src="https://cdn3.iconfinder.com/data/icons/pixomania/128/science-512.png" alt="science" id="science-img"> 
      <div class="description">
  <h2>Aerodynamically Tested</h2>
  <p>Gloves that have been tested time and time again to ensure the fastest strike. Testers may have been injured in the process.</p>
    </div>
    </div>
    <div id="sewing" class="glove-feature">
  <img src="https://cdn2.iconfinder.com/data/icons/eldorado-appliance/40/sewing_machine-512.png" alt="sewing" id="sewing-img">
      <div class="description">
  <h2>Hand-made</h2> 
  <p>Each and every glove is made in our Bangkok factory from scratch. That's the only way to make sure we deliver what we promise.</p> 
      </div>
    </div>
  </div>

<div id="features"> 
  <h2>In-Depth Look</h2>
  <iframe id="video" width="600" height="400" src="https://www.youtube.com/embed/xo2xuNYKO0I" frameborder="0" allowfullscreen></iframe>
</div>

<div id="pricing">
  <h2>Pricing</h2>
  <h3>$49.99</h3>
  <p>And if it doesn't last you 36 months...we'll give you a full refund.</p>
</div>

<div id="close">
  <form id="form" action="https://www.freecodecamp.com/email-submit">
    Take your bouts to the next level: <br>
    <input id="email" type="email" placeholder="Email" name="email"><br>
    <input id="submit" type="submit">
  </form>
</div>

查看

 angular.module('myApp.view2', ['ngRoute'])

    .config(['$routeProvider', function($routeProvider) {
      $routeProvider.when('/view2', {
        templateUrl: 'view2/view2.html',
        controller: 'View2Ctrl'
      });
    }])
    .controller('View2Ctrl', [$scope, function(){
        $scope.country = {
            name:"USA",
            age:500,
            year:100
        }

    }]);

当我调用{{country.name}}时,我的html返回字符串:“ {{country.name}}”

0 个答案:

没有答案