有角度重复/重复控制器的麻烦

时间:2015-10-30 08:09:15

标签: angularjs

我一直在学习angularjs 2天,在处理ng-controller / ng-repeat

时我无法工作
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <title>Angular test </title>
  </head>
  <body ng-app>
    Angular test 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <script>
        function menuCtrl($scope) {
          $scope.menus = [
            {title:"wiki",img:"../images/profil.png"},
            {title:"list",img:"../images/profil.png"},
            {title:"find",img:"../images/profil.png"},
            {title:"exp",img:"../images/profil.png"},
            {title:"stat",img:"../images/profil.png"},
            {title:"param",img:"../images/profil.png"}
         ];
       }
    </script>
    <div ng-controller="menuCtrl">
      <div ng-repeat="menu in menus">
        <a href="#"><img src={{menu.img}}></a>
        <h3>{{menu.title}}</h3>
      </div>     
    </div>
 </body>

2 个答案:

答案 0 :(得分:0)

角度1.4.7不支持这种编码方式,但角度<1.3.0支持。

我建议您遵循这种编码方式https://docs.angularjs.org/api/ng/directive/ngController

答案 1 :(得分:0)

ngApp:ng-app description

<body ng-app>

或者

<html ng-app>

使用此指令自动引导AngularJS应用程序。 ngApp指令指定应用程序的根元素,通常放在页面的根元素附近 - 例如在或标签上。

这会自动启动您的角度应用程序,然后一切都很好。但我喜欢在DOM ready事件上手动引导它。

它取决于你。如果你正在构建一个示例应用程序并尝试学习,那么ng-app对你来说很好,但是如果是大型应用程序,则需要制作模块。