导入角度js

时间:2017-08-29 10:31:03

标签: javascript angularjs



<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

  <div ng-app="myApp" ng-controller="myCntrl">
    First Name : <input type="text" ng-model="firstName"> <br>
    Last Name : <input type="text" ng-model="lastName"> <br>
    <br>
    Full Name: {{firstName + " " + lastName}}
  </div>

  <script>
  var person={
    firstName = "john" ,
    lastName = "Doe"
  };

  var app = angular.module('myApp', []);
  app.controller('myCntrl', function($scope){
    $scope.firstName = person.firstName;
    $scope.lastName = person.lastName
  });
  </script>
</body>
</html>
&#13;
&#13;
&#13;

但是我在运行时得到了这个

  

angular.js:38未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.6.4/ $ injector / modulerr?p0 = myApp&amp; p1 =错误%3A%20%5B%24injector%3Anomod%5D%20http%3A %2F%2Ferrors.angularjs.org%2F1.6.4%2F%24injector%2Fnomod%3Fp0%3DmyApp%0A%20%20%20%20原子%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs %2F1.6.4%2Fangular.min.js%3A6%3A425%0A%20%20%20%20原子%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min的.js%3A26%3A270%0A%20%20%20%20原子%20B%20(HTTPS%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js%3A25 %3A299)%0A%20%20%20%20原子%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js%3A26 3A44%%0A%20% 20%20%20原子%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js%3A42%3A117%0A%20%20%20%20原子%20Q% 20(HTTPS%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js%3A7%3A495)%0A%20%20%20%20原子%20克%20(HTTPS %3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4 %2Fangular.min.js%3A41%3A476)%0A%20%20%20%20原子%20EB%20(HTTPS%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular。 min.js%3A46 3A44%)%0A%20%20%20%20原子%20c的20%(HTTPS%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js %3A21%3A373)%0A%20%20%20%20原子%20SC%20(HTTPS%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.4%2Fangular.min.js%3A22% 3A179)   在angular.js:38   在angular.js:4920   在q(angular.js:403)   在g(angular.js:4880)   在eb(angular.js:4802)   at c(angular.js:1914)   在Sc(angular.js:1935)   at ue(angular.js:1820)   at angular.js:33367   在HTMLDocument.b(angular.js:3431)

任何帮助?

1 个答案:

答案 0 :(得分:1)

您必须在angular范围内使用正确的语法正确声明person对象。所以在控制器内移动你的对象。

&#13;
&#13;
  var app = angular.module('myApp', []);
  app.controller('myCntrl', function($scope) {
      var person = {
          firstName: "john",
          lastName: "Doe"
      };
      $scope.firstName = person.firstName;
      $scope.lastName = person.lastName
  });
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<body>
    <div ng-app="myApp" ng-controller="myCntrl"> First Name :
        <input type="text" ng-model="firstName">
        <br> Last Name :
        <input type="text" ng-model="lastName">
        <br>
        <br> Full Name: {{firstName + " " + lastName}} </div>
</body>

</html>
&#13;
&#13;
&#13;