0

A simple script to print the data using controller. I don't know where i am doing it wrong.. code consists of index.html, app.js and mail-list.component.js. mail-list.component is used to create template for view and registering the controller.

index.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>

app.js

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

mail-list.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 '
          }

        ];
      }

    });

3 Answers 3

3

You are using angular version 1.4.9, while components were introduced only in angular 1.5.*

See the migration guide for more details.

Sign up to request clarification or add additional context in comments.

3 Comments

i am using angular 2 on my machine, since i didn't find the online link for angular 2, so just for the sake to reference it wrote 1.4.9.
I don't think that Angular 2 has the angular global set. You may want to take a look at the angular 2 quick start guide.
This tutorial is written for Angular 1.5 so this must be the reason for confusion.
1

As Kazimieras said, the angular version doesn't have support for component().

In addition to his guide, I recommend this component polyfill by Todd Motto to backport components to Angular 1.3+.

Comments

-2

You seem to be missing an ng-app attribute on the tag.

2 Comments

which tag, you are talking about
its there on the html tag.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.