使用角度 JS 指令时出错

Error while using angular JS directives

本文关键字:指令 出错 JS      更新时间:2023-09-26

我是角度JS的新手,并尝试使用指令。

以下是指令的代码:

app.directive('appInfo', function() { 
  return { 
    restrict: 'E', 
    scope: { 
      info: '=' 
    }, 
    templateUrl: 'js/directives/appInfo.html' 
  }; 
});

以下是我的主要JS:

app.controller('MainController', ['$scope', function($scope) {
    $scope.apps = [
      {
        icon: 'img/move.jpg',
        title: 'MOVE',
        developer: 'MOVE, Inc.',
        price: 0.99,
        info: "move"
      }
    ]
}]);

现在,当我尝试在 html 中使用它时,我遇到了非常严重的错误,ia ma 无法忍受:

<div class="card" ng-repeat = "app in apps">
    <app-info info="{{ app.info }}"></app-info>
 </div>

在将数据传递给角度指令时,不需要使用插值,直接像这样传递数据:

<div class="card" ng-repeat = "app in apps">
  <app-info info="app.info"></app-info>
</div>

希望对您有所帮助。

你不需要在ng-repeat中传递{{}}

 <app-info info="app.info"></app-info>