Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS模型未将数据加载到视图中_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS模型未将数据加载到视图中

Javascript AngularJS模型未将数据加载到视图中,javascript,angularjs,Javascript,Angularjs,所以我遵循一个非常基本的AngularJS教程,发现 我已经完成了第10步,但是在我的视图中没有显示任何内容。有什么好处 以下是index.html的内容: <html> <head> <title>My Angular App!</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"><

所以我遵循一个非常基本的AngularJS教程,发现

我已经完成了第10步,但是在我的视图中没有显示任何内容。有什么好处

以下是index.html的内容:

<html>
  <head>
    <title>My Angular App!</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
    <script src="app.js"></script>
  </head>
  <body ng-app="flapperNews" ng-controller="MainCtrl">
    <div ng-repeat="post in posts">
        {{post.title}} - upvotes: {{post.upvotes}}
    </div>
  </body>
</html>

问题是您试图在任何角度上下文(即
MainCtrl
控制器)之外声明
$scope.posts

html


问题在于,您试图在任何角度上下文(即
MainCtrl
控制器)之外声明
$scope.posts

html


问题在于,您试图在任何角度上下文(即
MainCtrl
控制器)之外声明
$scope.posts

html


问题在于,您试图在任何角度上下文(即
MainCtrl
控制器)之外声明
$scope.posts

html


该死,我以为它存在于全球环境中。这是有效的,我会在七分钟内接受。实际上,Angular试图阻止您在全局上下文中创建任何内容。全局名称空间应该保持清晰,需要在其他组件中访问的任何内容都应该被注入。该死,我以为它存在于全局上下文中。这是有效的,我会在七分钟内接受。实际上,Angular试图阻止您在全局上下文中创建任何内容。全局名称空间应该保持清晰,需要在其他组件中访问的任何内容都应该被注入。该死,我以为它存在于全局上下文中。这是有效的,我会在七分钟内接受。实际上,Angular试图阻止您在全局上下文中创建任何内容。全局名称空间应该保持清晰,需要在其他组件中访问的任何内容都应该被注入。该死,我以为它存在于全局上下文中。这是有效的,我会在七分钟内接受。实际上,Angular试图阻止您在全局上下文中创建任何内容。全局名称空间应该保持清晰,需要在其他组件中访问的任何内容都应该被注入。
angular.module('flapperNews', [])
.controller('MainCtrl', [
'$scope',
function($scope){
  $scope.test = 'Hello world!';
}]);

$scope.posts = [
  {title: 'post 1', upvotes: 5},
  {title: 'post 2', upvotes: 2},
  {title: 'post 3', upvotes: 15},
  {title: 'post 4', upvotes: 9},
  {title: 'post 5', upvotes: 4}
];
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>My Angular App!</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-app="flapperNews" ng-controller="MainCtrl">
    <div ng-repeat="post in posts">
        {{post.title}} - upvotes: {{post.upvotes}}
    </div>
  </body>

</html>
angular.module('flapperNews', [])
  .controller('MainCtrl', [
    '$scope',
    function($scope) {
      $scope.test = 'Hello world!';

      // We are inside a controller here:
      $scope.posts = [{
        title: 'post 1',
        upvotes: 5
      }, {
        title: 'post 2',
        upvotes: 2
      }, {
        title: 'post 3',
        upvotes: 15
      }, {
        title: 'post 4',
        upvotes: 9
      }, {
        title: 'post 5',
        upvotes: 4
      }];
    }
  ]);