background preloader

Angular Gotcha's, Tips, Tricks & Best Practices

Facebook Twitter

Tip: directives with the same name. Since this blog is a blog for tips, let’s begin with the first one.

tip: directives with the same name

You want to log the clicks on a ng-click directive. What could you do? We can take this first approach: Try it NOTE: Check the logging on your browser’s dev tools console. That works. Alright, let’s take a different approach. This is the “original” (almost :P) ng-click directive with logging. What’s the problem? What can we do? We created a directive with the same name, which will log when we click. Conclusion By doing this we can write directives that we need to run when other directive appears. Random tricks when using AngularJS » Tomaka17's blog. If you don’t know AngularJS, it is a very good Javascript library that allows you to easily build web applications.

Random tricks when using AngularJS » Tomaka17's blog

Here are some random useful tricks that I found for AngularJS users. Ternary operator in expressions When you write an expression, like {{ id }}, you can’t use the ternary operator . But you can use the && and || operators. What stumped me about AngularJS. So I've now built my first real application using AngularJS.

What stumped me about AngularJS

It's a fun side-project which my wife and I use to track what we spend money on. It's not a work project but it's also not another Todo list application. In fact, the application existed before as a typical jQuery app. So, I knew exactly what I needed to build but this time trying to avoid jQuery as much as I possibly could. The first jQuery based version is here and although I'm hesitant to share this beginner-creation here's the AngularJS version. Git ready » learn git one commit at a time. Using the DOM in an AngularJS application - The Problem Solver. Using the DOM in an AngularJS application Index: Even though you should not manipulate the DOM in an AngularJS application but leave that up to AngularJS itself to do there are certainly places where you will need to interact with it.

Using the DOM in an AngularJS application - The Problem Solver

For example you might want to react to events and do something in reusable manner. Sure you can use the ngClick directive to react to a click but there are cases where you need to react to a click and don't want to repeat the same click handler each time. The place to add these kind of interactive DOM related code in AngularJS is in a directive and not in a controller. In the previous blog post I showed how to use a directive with a template to make our HTML smaller and more reusable, in this blog post I am going to show how you could implement your own version of ngClick. The Mooney Project » Angular JS: Navigator Pattern. New To AngularJS?

The Mooney Project » Angular JS: Navigator Pattern

Not sure what Angular JS is? The short version is that it is a client-side Javascript library. And unlike most of those libraries I’ve fooled around with, it’s very quick to get started with, and makes a lot of stuff really easy. Pulling data from JSON REST services. Hash-bang routing. Using Angular.js with ClojureScript. Related MicroZone Resources Like this piece? Share it with your friends: When I wrote my last post on ClojureScript , I was really hoping someone would jump in and say: “You’re doing it wrong! Quick AngularJS Tip: Relating User Input Data to Metadata. I started learning AngularJS a few weeks back because I thought it would work well for an internal tool I was building (more on that in a later post).

Quick AngularJS Tip: Relating User Input Data to Metadata

Many AngularJS examples, including those in the current AngularJS tutorial (like this one), illustrate how to use the ng-repeat and ng-options directives using a typical JavaScript array of objects. So, given such an array in the model: 1. $scope.plans= [ JumpStart Angular : Best Practices. In previous posts we have seen various aspects of AngularJS.

JumpStart Angular : Best Practices

We have seen model binding with ng-model, various angular directives like ng-app, ng-controller, ng-click, ng-repeat etc. Using these we can build highly interactive and dynamic website. So, it is the right time to get to know some of the best practices. Following these practices will improve code quality and helps us to overcome some hiccups. We will look into various examples explaining these and will try to follow these practices in further blog posts. 1. ng-app with application name. We have used ng-app in all our examples. ng-app defines the code block that is controlled by AngularJS. AngularJS Do’s and Dont’s. Since the past year, I have been observing the market and adoption of AngularJS in the wild.

AngularJS Do’s and Dont’s

I really like what I am seeing. It surely has come a long way from being called a toy framework, esoteric research framework to where it is today. Having worked with this framework from the start and having answered quite a few questions about it on Stack Overflow I have noticed a few common mistakes that people do when working with AngularJS. I will in this post attempt to address a few of these problems and what would be the right way to do the same.

DONT : Access DOM in the Controller This is the most common pitfall and probably the one that has been covered quite a lot in both the official site and elsewhere. I hope anyone who has been in the field of programming for any considerable time should have heard about the Law of Demeter. Rapid Prototyping with AngularJS. The idea hits you like a lightning bolt.

Rapid Prototyping with AngularJS

It’s inspiring, transfixing and gripping! You scribble down a design, grab your computer, fire up your tools and… spend the next ours banging your head against a wall of JavaScript as your inspiration slowly drains away. That’s not right – code should never get in the way of building a great idea. I’m going to show you a library called AngularJS that can help you get from inspiration to working prototype fast. It’s not designed as a rapid prototyping tool – in fact, it’s a full-featured MVC client-side JavaScript framework designed to allow you to add functionality to HTML… but you can get the marketing spiel elsewhere. There are a million and one “hello, world” Angular tutorials – hell, I wrote one – but today we’re not going to worry about the really simple stuff, you’re too good (looking) for that.

The Angular Way. This kind of interaction, data binding, and view synchronization would be easily be a maintenance nightmare if it wasn't for a framework such as Angular.

The Angular Way

Being able to update a model in one place, and have Angular update all relevant views almost feels like cheating. Adding, removing, or moving a layer is just a matter of changing an object. layer.x += 10, done. There's no need to invalidate the view by hand, or to manually update each instance of the layer in the DOM. Or to even interact with the DOM, for that matter. Angular enabled us to go places we wouldn't ever have dreamt of, such as setting up a bunch of keyboard shortcuts that are enabled based on the current context of the application. Similarly, we tacked a description onto these shortcuts (which are registered through a service we created), and we are then able to show a list of shortcuts, along with their descriptions, in a handy cheat sheet. Superspeed your angularjs apps. AngularJS renders HTML incredibly fast.But when rendering large DOM trees like containing tables with sort able columns, filtering and stuff ... it might get slower than you want ...While working on Orangevolt Ampere (which is heavily based on AngularJS) I realized a few remarkable performance tricks.The hints detailed in this article can improve AngularJS pages rendering up to 1000% and more - no kidding !

Performance is actually not a AngularJS problem - it's YOUR code. Kickstart Your AngularJS Development with Yeoman, Grunt and Bower. Whether you love or hate it, there’s no denying that AngularJS is the framework on every developer’s lips. It may not be for everybody, but AngularJS has a quirky, efficient and powerful feature set.

Couple that with a few useful development tools like Yeoman, Grunt and Bower and you’ve got yourself an incredibly fast rapid prototyping process. Angular.js : Advanced Design Patterns and Best Practices. Currently Open Tabs: Resources For Using AngularJS - Anti-Code.com. Jun 10, 2013 by Jared Williams Although this list is not actually a complete or accurate list of my currently open tabs (I have since closed some, as well as, working on a page for DevTools docs), this is a list of tabs I have either open, or have opened at one time. You may have noticed more and more recently, that Angular.js is growing in popularity among Front-end Developers.

I’m personally a big fan of it, and I would like to share some more things which I’ve come to learn about it in the near future. Until the, here’s a list of tabs which are mostly focused on developing with Angular.js, but a few others thrown into the mix as well. AngularJS Tips and Tricks - AngularJSChicago. Random tricks when using AngularJS » Tomaka17's blog. AngularJS is too humble to say you’re doing it wrong.

For years, web application developers have used DOM manipulation tools like jQuery to control their user interface. Astute developers have taken it to the next level with client-side templating tools like Mustache and Handlebars.js to build sophisticated user interfaces on the client side. And then AngularJS came along. And we all realized we’ve been doing it wrong. What are the "Best Practices" for getting data from a Rails Applicatio. AngularJS Dynamic Templates - Yes We Can! This is going to be a really fun post for me. AngularJS and recursive template. I love JavaScript.

It's like Lego, you can build anything really fast. AngularJS - Using Partials Dynamically Within Other Partials. Best practices for unit testing angular directives. I'm writing some unit tests for directives in AngularJS using Jasmine and Karma as my test runner. As I'm doing this, I'm wondering whether or not I'm following the best means of setting this up and was hoping someone could help me out. If my directives use a template by means of templateUrl, is it best to import the actual template, which has proved to be a bit tricky, or to insert a mock of the template using $templateCache and make my assertions of of that?

For unit testing, it would seem to me that creating mocks would be the best option because it avoids pulling in the additional resources which clutters up the point of unit testing. AngularJS tips'n'tricks part 2 - revolunet blog. AngularJS tips'n'tricks part 1 - revolunet blog. 4 Tips for a Great First-Use Experience.

By Warren Croce. ActiveRecord: When aggregating nested children, always exclude children marked for destruction. Posted about 2 years ago. Visible to the public. AngularJS tips and tricks for neophytes and the all-around curious developer. – bytes for thought. Article written as of AngularJS 1.0.7/1.1.5. Forget jQuery’s event handling altogether. I know it’s hard at first, but the temptation to use jQuery is the first and most common mistake developers make when starting out with Angular. It is so deeply engrained in our minds that you must force yourself to perform a paradigm shift. Angular.js Hacks. A couple of good things happened this week, I got a MacBook Pro (Retina Display) from my generous employer (which I setup promptly after the recent pain Linux distros have been giving me) and I got an underground car parking at work.

At 45 degrees, walking back to my car from my office was no easy feat and I am glad that now I've got a cool car (literally) waiting for me when I head home. Why its best practice to inject $rootScope and $controller unit testing controllers? $rootScope has some attached functionality. For example, $broadcast, $emit, $on (probably more than that). As such, supplying your own fakes might not test the actual behaviour. Best practices for unit testing angular directives. Testing Rails App with Testacular and AngularJs. Testing Rails App with Testacular and AngularJs. Modeset/teaspoon. Testing - How to setup Rails-Angular project to test JS. Angularjs - testacular / karma skips my e2e test. AngularJs e2e Testing: How to have expect() handle non-future objects. AngularJS: Expecting `expect` to Work as Expected. Scenario Test Runner: expect(1).toEqual(1) should pass. AngularJS Tips&Tricks. AngularJS unit testing. Angular Modules and RequireJS best practices? I Wish I Knew Then What I Know Now.

AngularJS tips and tricks for neophytes and the all-around curious developer. – bytes for thought. Angular.js : Advanced Design Patterns and Best Practices. I Wish I Knew Then What I Know Now. Code Organization in Large AngularJS and JavaScript Applications — Cliff Meyers. Quick AngularJS Tip: Relating User Input Data to Metadata. Behaviour of Scope in AngularJS Directives. Modeling Data and State in Your AngularJS Application.

AngularJS, Dependency Injection, and when is a singleton not a Singleton? AngularJS: What are the best practices to organize large angular projects. AngularJS: 6 Common Pitfalls Using Scopes – TNG - The Nitty Gritty. Angularjs - Angular - Best practice to structure modules. Angularjs - What is the best practice for making an AJAX call in Angular.js. AngularJS Best Practices - Jaco Pretorius. Why does Angular.js rock? Structuring an Angular Project. Simulating Latency for AngularJS $http Calls with Response Interceptors. Eburley.github.com. AngularJS – usin’ $apply. Learn AngularJS in 5 steps - revolunet blog. AngularJS and a JS prototypal inheritance gotcha. Angular.js real app experience, problems and solutions at Belarus Ruby on Rails User Group meetup.

AngularJS: What are some time-saving tips every AngularJS user should know. AngularJS: What are some tips, tricks and gotchas when using AngularJS. AngularJS: What are some undocumented bugs/gotchas when using AngularJS in Internet Explorer. Angularjs - When writing a directive, how do I decide if a need no new scope, a new child scope, or a new isolate scope. Recommendations for large single page application with 'portal' or MDI like functionality using AngularJS. AngularJS Modules for Great Justice.

AngularJS Pain Points - Jaco Pretorius. 5 AngularJS Power Features that are awesome in non-trivial webapps. Modeling Data and State in Your AngularJS Application. AngularJS tips'n'tricks part 2 - revolunet blog. AngularJS Tips and Tricks [UPDATED] ☢ DeanSofer.com. Lessons Learned: A Year with a Large AngularJS Project. Using AngularJS? Stop using jQuery as a crutch. Some AngularJS pitfalls - Branch and Bound. Brian Ford. Adventures in Software With Joel Hooks - @jhooks. What stumped me about AngularJS. iPhone, Android, Blackberry, PHP, Generatrix, Wordpress App Development in Pune, India. Some opinions on developing with AngularJS. Things I have learned working with AngularJS.

Things I Wish I Were Told About Angular.js. 4 Lessons Learned Doing Angular on Rails. AngularJS MTV Meetup: Best Practices (2012/12/11)