Tuesday, October 27, 2015

Angular2: Fix Displaying data example in es5

Since I’m recently working on an angular project, I started to get curious about the angular 2 version. I started with the quick start demo and everything went very smooth. So the next step was the Displaying Data example. It was then when it started to get wrong. I was following the walkthrough, but the result I got was a blank page.

After some research I discovered that that the angular developers made a breaking change in the alpha 35 version. All the classes ending on Annotation(s) where renamed to Metadata. Another difference is that you need to use the ng object instead of angular on the window.

If you want to get the Displaying Data example to work in es5, you will need to do the following:

show-properties.js:

   1: (function () {
   2:     // ES5
   3:     function DisplayComponent() {
   4:         this.myName = "Alice";
   5:     }
   6:  
   7:     DisplayComponent.annotations = [
   8:         new ng.ComponentMetadata({
   9:             selector: "display"
  10:         }),
  11:         new ng.ViewMetadata({
  12:             template:
  13:                 '<p>My name: {{ myName }}</p>'
  14:         })
  15:     ];
  16:  
  17:     document.addEventListener('DOMContentLoaded', function () {
  18:         ng.bootstrap(DisplayComponent);
  19:     });
  20: })();

 


<html>
<head>
    <script src="angular2.sfx.dev.js"></script>
    <script src="show-properties.js"><script>
</head>
<body>
    <display></display>
</body>
</html>

19 comments:

  1. Thank you! It helped me very much!

    ReplyDelete
  2. It should be helpful but it wasn't really clear. Thank you for sharing those tips. I would like to ask you to make them more detailed.

    ReplyDelete
  3. This blog is really great.This site is very helpful and informational : click here

    ReplyDelete
  4. Each optical disc is able to store as much data as five hundred floppy disks. Thus, storage of data and retrieval is easier and much faster now. Self Storage

    ReplyDelete
  5. i have a couple of friends who work as network administrators and would probabbly use this kind of help thanks for sharing such an awesome piece il refer them to your blog

    ReplyDelete


  6. Mobility| Austere Technologies

    REALLY VERY EXCELLENT INFORMATION. THIS BLOG IMFORMATION VERY GOOD AND WE ALSO PROVIDING BEST SERVICES.

    ReplyDelete
  7. you helped me a lot, I work as an intern and did not know how to accomplish the task, but you corrected everything and helped me

    ReplyDelete
  8. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    software security Services | Austere Technologies

    ReplyDelete
  9. Really great blog, it's very helpful and has great knowledgeable information. Thanks for sharing.

    Best Software Company in USA | Austere Technologies

    ReplyDelete
  10. Looking really very informative impressed very much with this blog, like to watch regularly to get more updates...
    Best Online Software Training Institute | Data Science Training

    ReplyDelete
  11. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.
    Best Commerce College| Avinash college of commerce

    ReplyDelete
  12. Wow...What an excellent informative blog, really helpful. Thank you.

    Best Commerce College in Hyderabad | Avinash College of Commerce

    ReplyDelete
  13. Nice Blog Thank providing Useful Information
    It Training

    ReplyDelete
  14. Thank you for sharing this valuable information. But get out this busy life and find some peace with a beautiful trip. book Andaman Nicobar Tour Packages @ 11599

    ReplyDelete
  15. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Deops training in annanagar

    Devops training in chennai

    Devops training in marathahalli

    Devops training in rajajinagar

    Devops training in BTM Layout

    ReplyDelete
  16. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Data science training in tambaram
    Data science training in kalyan nagar
    Data Science training in OMR
    Data Science training in anna nagar
    Data Science training in chennai
    Data Science training in marathahalli
    Data Science training in BTM layout
    Data Science training in rajaji nagar

    ReplyDelete
  17. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    java training in chennai | java training in bangalore

    java online training | java training in pune

    selenium training in chennai

    selenium training in bangalore

    ReplyDelete
  18. The advice is always the same: publish quality content. But where? On your profile, it's clear. But you can do it in different ways. For example, you can use the official feed with posting photos and collages.https://buymorefollower.com/

    Then there are the mini-videos that work well. But what gives your profile great visibility, with relative increase in followers, is the work on Instagram Stories. Without forgetting the possibility of operating also with the video content marketing of IGTV, the Instagram television.
    All this helps to create a variety of useful content to increase the potential audience you want to add to the potential followers of the profile.

    ReplyDelete