background preloader

Controllers

Facebook Twitter

Angular JS: Using ngResource in a more RESTful manner. A key problem I found (due to how I like to work) is that the $save method on ngResource will only ever issue POST requests to the server, along with the payload.

Angular JS: Using ngResource in a more RESTful manner

This is true for both create and update operations - aka, both new and old objects from our server. This breaks RESTful conventions as update operations should be done with PUT or PATCH. My proposed solution below extends the current ngResource implementation, and provides more defaults, whilst streamlining our workflow. The perfect use-case (imho) should be like below: If we dig into the ngResource code - such a requirement is impossible, due to how the simple the implementation is (much to the Angular team’s credit).

Update: Resolved the save method not returning results - thanks bpetering! Here we’re defining a custom module - my.resource. First, we define our new defaults. Below this we’re extending the defaults with any methods you may have provided to the resource itself. It’s really that simple. Namespacing Angular Controller Attributes - Jake Trent. Usually attributes of your Angular controllers are not namespaced.

Namespacing Angular Controller Attributes - Jake Trent

But you can namespace them. But you might not want to. How To Test An AngularJS Directive - Newtriks LTD. Written by Simon Bailey After working with Backbone, Meteor, AngularJS and Ember (however, I have not dived deep into Ember yet), I feel that AngularJS is prepared the best for Test Driven Development (TDD).

How To Test An AngularJS Directive - Newtriks LTD

It truly makes it a cinch removing all excuses to not use tests in your application! I have had the pleasure of focusing on testing within an AngularJS client application recently and lost a small amount of time testing a directive. The issue revolved around the template being located as an external html file as opposed to being included within the directive itself. Rb: Displaying json array data with Angular JS and ng-grid. In many projects there comes a time when you’ll need to list some data.

rb: Displaying json array data with Angular JS and ng-grid

It may be a requirement or just an improvement for your users to show the list of products, but you have to decide which of the available options you will use in your application. This article will help you choose the best one, for your app. In past, i’ve used tables or unordered list a lot bit in the past. So manipulating the data can be tough. Thankfully there are some libraries available and that have built in functionality for sorting, searching, grouping data, etc. Dynamically Loading Controllers and Views with AngularJS and RequireJS - Dan Wahlin.

Dynamically Loading Controllers and Views Updated: August 30th, 2014 A complete sample application that uses the techniques shown in this post can be found at AngularJS provides a simple way to associate a view with a controller and load everything at runtime using the $routeProvider object.

Dynamically Loading Controllers and Views with AngularJS and RequireJS - Dan Wahlin

Routing code is typically put in a module’s config() function and looks similar to the following: While this type of code works great for defining routes it requires controller scripts to be loaded upfront in the main shell page by default. This approach works well in cases where you don’t want all of your controller scripts loaded upfront, but it still doesn’t feel quite right – at least to me. Notice that a single value is passed into the route.resolve() function. Dynamically Loading Controllers The following diagram shows the different players involved in simplifying routes and dynamically loading controllers. Here’s how it works: AngularJS: Listening for $destroy. Sharing data across controllers – Angular JS & CoffeeScript by Mike Coutermarsh. AngularJS Controller Tutorial. AngularJS Controller example.

Let us talk about one of the AngularJS’s most useful feature which helps in making awesome single page applications in JavaScript – The Controller.

AngularJS Controller Tutorial. AngularJS Controller example

This tutorial is part of series of tutorials on AngularJS where we shall touch different aspects of Angular and its features. In our last tutorial we saw Introduction of AngularJS and also created a Hello World example using Angular. Controllers are nothing but plain JavaScript functions which are bound to a particular scope. Don’t worry if this sounds gibberish. Shortly this all will make sense once we create a small Hello World using controller. 1.

Demo - Annotator - Annotating the Web. An introduction to AngularJS. When I came across AngularJS a couple weeks ago, I was intrigued at first.

An introduction to AngularJS

By the time I had worked through the set of tutorials available on the AngularJS website, I was thrilled to have found this framework. What is AngularJS? AngularJS is the (relatively) new kid on the coding block. To quote from their website it is “a structural framework for dynamic web apps” which is especially well-suited for building one-page web apps, although it’s certainly not limited to that. Developed in 2009 by Miško Hevery and Adam Abrons — both Google employees at that time — it is entirely JavaScript and entirely client-side, so anywhere JavaScript can run, AngularJS can run. According to Wikipedia the goal of Angular “is to augment browser-based applications with model–view–controller (MVC) capability” and it does just that, providing a binding/MVC framework.

NgContextMenu. AngularJS - Communication Between Controllers. Controller Inheritance in AngularJS. I was looking for abstracting common functionality into base controllers to make them reusable.

Controller Inheritance in AngularJS

I took a look at typical JavaScript Inheritance patterns and particularly liked Functional Mixins approach outlined in this article . I followed along and no surprises - everything worked fine. Only one small thing bothered me - dependency injection. A base controller might need a different set of dependencies and there was no clean way of separating dependencies for base and child controllers. That's when I stumbled upon this gem by Misko on the Angular mailing list. Modular Controllers. Binding to an AngularJS Controller.