deeleman / learning-angular2

Code samples repository for the examples provided in "Learning Angular 2", published by Packt Publishing - THE BOOK COVERS UP TO RC.1 and hence is severely OUTDATED. PLEASE REFER TO THE LATEST EDITIONS INSTEAD.
https://www.packtpub.com/web-development/learning-angular-2
108 stars 59 forks source link

First example errors #2

Closed sabas closed 8 years ago

sabas commented 8 years ago

I believe these are due to the beta changing from beta0 to beta1.

Page 7 there's a typo (missing a comma) in

@Component({
 selector: 'my-app'
 template: '<h1> {{greet}} </h1>'
})

so the output is app.ts(6,2): error TS1005: ',' expected.

When fixed the error becomes

app.ts(1,1): error TS6053: File 'node_modules/angular2/angular2.d.ts' not found.
app.ts(2,38): error TS2307: Cannot find module 'angular2/angular2'.
sabas commented 8 years ago

The solution is to change the import to

import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';

http://stackoverflow.com/questions/34697466/cannot-find-module-angular2-angular2

Also the first row (/// <reference) is not needed?

Then I got a bunch of Duplicate identifier errors, which I fixed changing in tsconfig.json the target from es2015 to es5

deeleman commented 8 years ago

Yes, we are well aware of that: Unfortunately the code currently available in the PDF chapter still refers to Alpha 37 or so, which is a billion versions back in regars of the current beta.1. Remember that the chapters supplied in the alpha book have not gone through technical review and proper proofreading yet (hence the "alpha" label) so bugs and inaccuracies are still common in this early versions.

In a few days or weeks time you guys will receive updated versions of the first chapters, reflecting the latest incarnation of the framework API. In the meantime, please refer to the code examples in this repository, which happen to be fully in sync with the current state of Angular 2.

Thanks for the catch regarding the missing comma! :)

And now for the issues reported:

app.ts(1,1): error TS6053: File 'node_modules/angular2/angular2.d.ts' not found.

In the beginning we were forceed to rely on the type definitions to ensure proper compilation. That is no longer needed. So you can safely remove the /// <reference... from your code.

app.ts(2,38): error TS2307: Cannot find module 'angular2/angular2'.

As you discovered yourself already, this token was substituted by angular/core as for Alpha 53. Two versions later the framework transitioned into Beta stage.

Please refer to the code in this very same repo for further reference. Chapter 1 is alrady available and dully in sync with Beta.1. The code for the next chapters will go live in the forthcoming days.

sabas commented 8 years ago

Thanks a lot!

deeleman commented 8 years ago

You're welcome Stefano. Keep an eye on this repo for the most updated version of the code examples. Updated code examples pertaining to chapters 3 and 4 will hit the repo shortly.