Live data from Hacker News

Diving into AngularJS

floatleft.com

21–30 of 48 posts

Re: Diving into AngularJS

#21

Why am I just noticing the "by Google" under the logo?!

That's actually one of the more interesting parts about Angular. I'm not sure of the details but I believe the Angular team have been counting on Object.observe for increasing the performance of the Angular code [0] (something that Google / the Chrome team have influence over).

The Angular code you write now won't need to be updated and will get a great speed boost later. Other libraries, like Ember, get you to add all that metadata to your code to give you a performance boost now (which to me feels like something you'll regret in a year's time).

Ah, this is the post I was looking for [1].

[0] http://blog.angularjs.org/2012/07/angularjs-10-12-roadmap.ht...

[1] https://plus.google.com/112439678898563138768/posts/RZKRBiGX...

Re: Diving into AngularJS

#22
The more I use Angular, the more I love it. I like how it's really easy to get started with it. Just avoid writing your own directives right away, that's still the one part that is super confusing (although powerful).

Re: Diving into AngularJS

#23
post #16

Earlier quoted context omitted.

Probably, as that doesn't seem like a good reason.

Quite. But how much effort they put in their website and documentation is somehow important to me. Then again, Ruby projects always look glamorous while Haskell projects (just an example for an exotic language) look like some HTML document someone wrote 10 years ago on an university computer. Ember.js in comparison has a certain glow to it. Especially with that weird mascot.

Eh, some Haskell projects are improving their design. The web-frameworks certainly have[1][2].

[1]: http://www.yesodweb.com/

[2]: http://snapframework.com/

It's progress.

Re: Diving into AngularJS

#25

The more I use Angular, the more I love it. I like how it's really easy to get started with it. Just avoid writing your own directives right away, that's still the one part that is super confusing (although powerful).

What do you wish you knew about writing directives then that you know now? Or what did you find confusing?

I am currently writing a book on Angular and would like to know. I remember I had a lot of trouble on how to write a reusable component defined in a partial, and what to pass into the directive constructor.

Re: Diving into AngularJS

#27

The more I use Angular, the more I love it. I like how it's really easy to get started with it. Just avoid writing your own directives right away, that's still the one part that is super confusing (although powerful).

What do you wish you knew about writing directives then that you know now? Or what did you find confusing? I am currently writing a book on Angular and would like to know. I remember I had a lot of trouble on how to write a reusable component defined in a partial, and what to pass into the directive constructor.

Hey Kevin, this isn't about directives but about RESTful services and $resource. I started learning how to use AngularJS yesterday and all of the examples that I've found on it are confusing to me and seem to do it in different ways.

I've seen somebody do it by calling myModule.factory. I've seen an example on Stackoverflow that says all you need to do is something like var Todo = $resource('/api/1/todo/:id');. I'm not sure where I'm supposed to put this code. I want to be able to use the resource globally but I don't have access to $resource in the global namespace.

All I'm trying to do is make a simple blog that can interact with my backend. If you have this part of the book written I'd love to read it right now.

EDIT: I figured out how to do it I think. But I'd still love a more complete introduction to using Angular with a RESTful service.

Re: Diving into AngularJS

#29

Hey Andy, please consider choosing a more readable font for your blog. I would love to read this article, but the thin font is hurting my eyes.

Thanks for the feedback - I've been wondering about this for a while and you're right. It's just finding something that will work well!

Re: Diving into AngularJS

#30
post #27

Earlier quoted context omitted.

What do you wish you knew about writing directives then that you know now? Or what did you find confusing? I am currently writing a book on Angular and would like to know. I remember I had a lot of trouble on how to write a reusable component defined in a partial, and what to pass into the directive constructor.

Hey Kevin, this isn't about directives but about RESTful services and $resource. I started learning how to use AngularJS yesterday and all of the examples that I've found on it are confusing to me and seem to do it in different ways. I've seen somebody do it by calling myModule.factory. I've seen an example on Stackoverflow that says all you need to do is something like var Todo = $resource('/api/1/todo/:id');. I'm n…

Personally I found using $http less restrictive - there seem to be some edge cases where $resource behaves oddly. Ideally what you should be doing with REST calls is pushing them out to Angular Services (http://docs.angularjs.org/guide/dev_guide.services.creating_...) rather than making them directly in your controller.

Here's a simple example:

  appServices.factory('Thing', function($http) {

    var Thing = function(data) {
      angular.extend(this, data);
    }

    Thing.all = function() {
      return $http.get('/things).then(function(response) {
        return new Thing(response.data);
      });
    }

    Thing.get = function(id) {
      return $http.get('/things/' + id).then(function(response) {
        return new Thing(response.data);
      });
    }

    Thing.delete = function(id) {
      return $http.delete('/things/' + id).then(function(response) {
        return new Thing(response.data);
      });
    }

    Thing.create = function(data) {
      return $http.post('/things', data).then(function(response) {
        return new Thing(response.data);
      });
    }

    Thing.update = function(data, id) {
      return $http.put('/things/' + id, data).then(function(response) {
        return new Thing(response.data);
      });
    }

    return Thing;
  });
In your controller, inject the service:

  function thingCtrl($scope, Thing) {
    Thing.all().then(function(data) {
      $scope.things = data;
    });
  }
  thingCtrl.$inject = ['$scope', 'Thing'];
Post reply on HN