0

使用控制器打印数据的简单脚本。我不知道我在哪里做错了。代码由 index.html、app.js 和 mail-list.component.js 组成。mail-list.component 用于创建用于查看和注册控制器的模板。

索引.html

<!doctype html>
<html lang="en" ng-app="mailApp">
<head>
<meta charset="utf-8">
<title>Mail System</title>
<link rel="stylesheet" href="css/style.css">
<script src = "angular.min.js"> //angular 2
</script>
<script src="app.js"></script>
<script src="mail-list.component.js"></script>
</head>

<body>
<!--use a custom component to render the mails-->
<mail-list></mail-list>
</body>
</html>

应用程序.js

'use strict';
// Define the 'mailApp' module
angular.module('mailApp', []);

邮件列表.component.js

'use strict';
// Register `mailList` component, along with its associated controller and template

    angular.
      module('mailApp').
        component('mailList',{
          template:
        '<span ng-repeat="mail in $ctrl.mails"> '+
        '<input type="checkbox"><b>{{mail.sender }}:<i> {{mail.subject}}</i></b> {{ mail.message}}</span>',

      controller: function MailListController(){
        this.mails=[
          {
            sender: 'Monu',
            subject: 'Regarding Gate',
            message:'start preparing or gate 2017 exam, dont miss this time'
          },{
                sender: 'Shiv',
                subject: 'College Over',
                message:'B.tech is over, now i am a graduate, hurrey!!'
          },{
            sender: 'Monu',
            subject: 'Regarding bag',
            message:'purchase a new bag for me '
          }

        ];
      }

    });
4

3 回答 3

3

您使用的是 Angular 1.4.9 版本,而组件仅在 Angular 1.5 中引入。*

有关更多详细信息,请参阅迁移指南

于 2016-06-06T12:12:19.443 回答
1

正如 Kazimieras 所说,角度版本不支持component().

除了他的指南之外,我还推荐 Todd Motto 的这个组件polyfill,以将组件反向移植到 Angular 1.3+。

于 2016-06-08T13:23:43.473 回答
-2

您似乎缺少标签上的ng-app属性。

于 2016-06-06T12:09:35.847 回答