代码之家  ›  专栏  ›  技术社区  ›  fralbo

1.2.29版之后如何使用NG控制器?

  •  0
  • fralbo  · 技术社区  · 6 年前

    我正在学习一个基于1.2版的AngularJS教程,我发现它在最新的1.7.2版上不起作用。 经过几次测试,我意识到它在1.3+版本上不起作用,但是根据文档,在 ng-controller 使用。

    我的代码是:

        <div id="example" ng-controller="CommentsCtrl">
            <div ng-repeat="comment in comments | filter:{content: query} | orderBy: order">
                <p>
                    <strong>{{comment.username}}</strong><br/>
                    {{comment.content}}
                </p>
            </div>
        </div>
    
       <script>
            function CommentsCtrl($scope) {
    
                $scope.comments=[
                    {
                        "username": "Geraldine",
                        "city": "Dola",
                        "email": "geraldinemaddox@enervate.com",
                        "content": "Dolor consectetur..."
                    },
                    ...
                ]
            }
        </script>
    

    为了让您更好地了解问题,代码如下: jsfiddle

    请问怎么了?

    1 回复  |  直到 6 年前
        1
  •  0
  •   BShaps    6 年前

    angular.module("app", [])
    

    <body ng-app="app">
    

    angular.module("app").controller('CommentsCtrl', function CommentsCtrl($scope) {
      // Controller code here
    });
    

    jsfiddle fork