AngularJS:为什么ng-repeat不起作用?

时间:2016-12-21 15:27:40

标签: angularjs

请查看以下代码:

waitpid()

我希望看到三个<html lang="en" > <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="flexbox" > <div id="wrapper" ng-controller="flex-ctrl as ctrl"> <div id="aside"> <p ng-repeat="item in ctrl.buttons"> {{item}} </p> </div> </div> </body> </html> var app = angular.module("flexbox", []); app.controller("flex-ctrl", ['$scope', function($scope) { $scope.buttons = ['a','b', 'c']; }]); 项。但是,看起来ng-repeat被忽略了,我看到一个空页面。

你知道这是什么问题吗?

为方便起见:http://codepen.io/CrazySynthax/pen/yVwWdo

3 个答案:

答案 0 :(得分:2)

使用this.buttons代替$ scope.buttons,因为您使用的是controller as语法

&#13;
&#13;
var app = angular.module("flexbox", []);
app.controller("flex-ctrl", ['$scope', function($scope) {
  this.buttons = ['a','b', 'c'];
}]);
&#13;
<!DOCTYPE html>
<html>
<head>
   <script data-require="angular.js@1.4.7" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
</head>
<body ng-app='flexbox'>
    <div id="wrapper" ng-controller="flex-ctrl as ctrl">
      <div id="aside">
        <p ng-repeat="item in ctrl.buttons"> {{item}} </p>
      </div>
  </div>
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

由于您使用控制器作为语法,您可以像这样更改您的ctrl:

MERGE INTO (SELECT * FROM TEST_HISTORY WHERE TH_Valid_To_Date = to_date('3000-01-01','yyyy-mm-dd'))             Hst /*change only current records which are identified by TH_Valid_To_Date = to_date('3000-01-01','yyyy-mm-dd') */
   USING (
      SELECT * FROM (
         SELECT NVL(Src.T_Key_1, Dst.T_Key_1)                                AS T_Key_1
            ,NVL(Src.T_Key_2, Dst.T_Key_2)                                   AS T_Key_2
            ,Src.Text_Value
            ,Src.Number_Value
            ,Src.Amount
            ,CASE WHEN Src.T_Key_1 is null                                   THEN 'D' /*delete*/
                  WHEN Dst.T_Key_1 is null                                   THEN 'I' /*insert*/
                  WHEN (Src.Text_Value=Dst.Text_Value OR (Src.Text_Value is null AND Dst.Text_Value is null))
                       AND (Src.Number_Value=Dst.Number_Value OR (Src.Number_Value is null AND Dst.Number_Value is null))
                       AND (Src.Amount=Dst.Amount OR (Src.Amount is null AND Dst.Amount is null))
                                                                             THEN 'X' /*no change*/
                                                                             ELSE 'U' /*update*/ END  AS Operation  
         FROM TESTS                                         Src
         FULL JOIN (SELECT * FROM TEST_HISTORY WHERE TH_Valid_To_Date = to_date('3000-01-01','yyyy-mm-dd'))     Dst
            ON (Src.T_Key_1 = Dst.T_Key_1 AND Src.T_Key_2 = Dst.T_Key_2)
      )
      INNER JOIN (SELECT LEVEL AS duplication FROM DUAL CONNECT BY LEVEL BETWEEN 1 AND 2) ON (duplication=1 OR Operation='U') /*need to duplicate update records so that they can go to both matched and not matched parts*/
      WHERE Operation<>'X'
   )                                                                          Act
   ON (Act.T_Key_1 = Hst.T_Key_1 AND Act.T_Key_2 = Hst.T_Key_2 AND Act.duplication=1 AND Act.operation<>'I')

WHEN MATCHED THEN UPDATE
   SET
      TH_Valid_To_Date                              = p_Load_Date - 1,
   WHERE Hst.TH_Valid_To_Date                       = to_date('3000-01-01','yyyy-mm-dd')

WHEN NOT MATCHED THEN INSERT /*+ append */
   (
       T_Key_1                       
      ,T_Key_2                       
      ,Text_Value                    
      ,Number_Value                  
      ,Amount                        
      ,TH_Valid_From_Date             /*Auditní sloupec*/
      ,TH_Valid_To_Date               /*Auditní sloupec*/
   ) VALUES (
       Act.T_Key_1                       
      ,Act.T_Key_2                       
      ,Act.Text_Value                    
      ,Act.Number_Value                  
      ,Act.Amount                        
      ,p_Load_Date                    /*Auditní sloupec*/
      ,to_date('3000-01-01','yyyy-mm-dd') /*Auditní sloupec*/
   )
;
希望它有所帮助。

答案 2 :(得分:1)

您的变量位于$scope,因此您只需使用以下内容循环:

<p ng-repeat="item in buttons"> {{item}} </p>

而不是

<p ng-repeat="item in ctrl.buttons"> {{item}} </p>

<强> Forked your Codepen here.