pbastowski / angular2-now

Angular 2 @Component syntax for Angular 1 apps
MIT License
145 stars 15 forks source link

$onInit #54

Closed dgtlmonk closed 8 years ago

dgtlmonk commented 8 years ago

Hi and thanks for this awesome library :)

I was wondering if Angular 1.5 syntax $onInit is supported? What version of angular is this library currently using?

Kind regards.

pbastowski commented 8 years ago

@dgtlmonk Yes it is. $onInit is declared on the class itself, as shown below:

HTML

<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
  <script src="https://npmcdn.com/angular2-now@1.1.6/dist/angular2-now.js"></script>
</head>
<body>

  <app></app>

</body>
</html>

JavaScript

var {Component, bootstrap, SetModule, options} = angular2now;

options({controllerAs: 'vm'})
SetModule('app', []);

@Component({
  selector: 'app',
  template: `<h2>Hello World</h2>`
})

class App {
  $onInit () {
    console.log('component loaded')
  }
  constructor() {
    console.log('@App')
  }
}

bootstrap(App);