Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The new DI looks confusing. The old way is super simple to understand. You inject the location provider and call it. In the new way however I don't understand what's going on at all.

Where can I find a simple example?





I don't understand how that correlates to the current DI.

How do I rewrite the following using the new DI system?

  function MyCtrl($http, Base64) {
  	$http.get('http://www.example.com').success(function (data) {
  		console.log(Base64.decode(data));
  	});
  }


  import {Http} from 'angularjs/http';
  import {Base64} from './base64';

  @Inject(Http)
  @Inject(Base64)
  export class MyCtrl {
    constructor(Http, Base64) {
      Http.get('http://www.example.com').success(function (data) {
        console.log(Base64.decode(data));
      });
    }
  }
Not too bad, right?


I don't like it at all; the Http and Base64 imports require three tokens / lines to import, while the existing DI just needed one. RequireJS requires two (array entry, callback parameter).

I'll stick to ES 5 / Angular 1.2 if we're required to write this much boilerplate to achieve the same thing.


Isn't this line missing?

  import {Inject} from 'di/annotations';




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: