Angular helper to encode object as www/formdata

Helper to serialize data to www/formdata – needed for turning a javascript object into encoded form data to POST:

Angular Directives – compile & link & trusted HTML

More information on Angular directives:

Here’s a simple directive with a couple of scope variables that get displayed:

Here is the angular stuff:

Here is a fiddle for the example, which has some css and things. Nothing really special here.

Now, in order to make some DOM changes, we can’t change the element during the link function. If you want to change the element, you have to do it during the compile function. The compile function gets called when the directive is created, and should return the link function. This allows the directive to be modified. This example shows how to add a list to the directive.

We can also add some HTML with the “sce” module:

The interesting thing there is the compile function. The compile function gets the tElem, which is the template element itself. This function is run when the directive is compiled, and there is no scope available. We can, however, add some elements to the directive. Note that the compile function returns the link function.

Here is a working fiddle

Here’s a final fiddle showing how to add a list to the element’s div

Angular

JQuery how to resize table and keep table size

When removing a table row, you can prevent an html table size from changing by setting the width explicitly before removing the row:


 

Javascript function application / currying / callbacks

Javascript partial functions:Here, doSomething is a callback and the second argument should be data from a JQuery ajax call.Say you have a function:


There can be any number of arguments after passing in the function argument, like: partial(fn, arg1, arg2, …, argn), these arguments are applied to the function you will be calling.


 

The callback after the post will behave just like you called: doSomething(“Test Value”, data) where data is the $.post result.

 

Synchronous JavaScript for image validation

This function will return an image link if the url passed in is valid, otherwise it will return the no-image text. This is synchronous ajax, which will block your UI, but I use it for popover generation with bootstrap js, and it works just fine.