在Angular js beginner

时间:2017-08-10 15:49:49

标签: angularjs

我是Angular js的初学者。我已经编写了代码,但我得到了以下输出。你能纠正我的代码吗?

这是index.html:     

<body>
  <div ng-controller="MainController">
    {{ value }}
    <h1>Hello, world</h1>
  </div>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
  <script type="text/javascipt" src="app.js"></script>
</body>

</html>

这是App.js中的代码:

angular.module('app',[]); 
var MainController = function($scope){ $scope.value="This is Angular" }

但是我收到了这个输出:{{ $scope.value }} Hello, world

我已经验证了控制台,但我收到了错误消息。点击[here(https://docs.angularjs.org/error/ $ injector / modulerr?p0 = app&amp; p1 =错误:%20%5B $ injector:nomod%5D%20http: %2F%2Ferrors.angularjs.org%2Fundefined%2F $注射器%2Fnomod%3Fp0%3Dapp%0A%20%20%20%20个原子%20https:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1。 2.0%2Fangular.min.js:6:453%0A%20%20%20%20个原子%20https:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0%2Fangular.min.js:20 :119%0A%20%20%20%20原子%20A 20%(HTTPS:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0%2Fangular.min.js:19:353)%0A %20%20%20%20个原子%20https:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0%2Fangular.min.js:20:14%0A%20%20%20%20原子% 20https:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0%2Fangular.min.js:28:434%0A%20%20%20%20原子%20Array.forEach%20(%3Canonymous% 3E)%0A%20%20%20%20原子%20Q%20(HTTPS:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0%2Fangular.min.js:7:261)%0A %20%20%20%20原子%20E%20(HTTPS:%2F%2Fajax.googleapis.com%2Fajax%2Fli BS%2Fangularjs%2F1.2.0%2Fangular.min.js:28:374)%0A%20%20%20%20原子%20Xb%20(HTTPS:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs% 2F1.2.0%2Fangular.min.js:32:427)%0A%20%20%20%20原子%20c的20%(HTTPS:%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0% 2Fangular.min.js:17:315)

1 个答案:

答案 0 :(得分:0)

按如下方式更改您的app.js代码,

 var app = angular.module('app',[]);
 app.controller('MainController',function($scope){
     $scope.value="This is Angular";
 });

<强>样本

&#13;
&#13;
 var app = angular.module('app',[]);
app.controller('MainController',function($scope){
   $scope.value="This is Angular";
});
&#13;
 <html ng-app="app">
  <body>
            <div ng-controller="MainController">
            {{ value }}
            <h1>Hello, world</h1>
            </div>
            <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
      
</body></html>

      
&#13;
&#13;
&#13;