AngularJs: intersting syntax for complex ng-class conditions

Just now I got known quite interesting condition syntax for ng-class (from stackoverflow answer):

[javascript gutter=”0″]
ng-class="{admin:’enabled’, moderator:’disabled’, ”:’hidden’}[user.role]"
[/javascript]

it seems that there is not good explanation for such case in documentation.
being inspired by this possibility I decided to create even more complex condition:
[javascript gutter=”0″]
ng-class="connections.length && ({true:’open’, false:’close’}[!!manager.showConnections])"
[/javascript]

(flag open/close will be shown only if there are some connections for current manager)

Angular one-time binding cheat sheet

ng-bind:

[javascript gutter=”0″]
{{ ::user.name }}
[/javascript]

with filters

[javascript gutter=”0″]
{{ ::item.price|number }}
[/javascript]

ng-class:

[javascript gutter=”0″]
<div ng-class="::{ ‘active’: item.active }"></div>
[/javascript]

ng-if:

[javascript gutter=”0″]
<div ng-if="::user.isOnline"></div>
[/javascript]

with several conditions:

[javascript gutter=”0″]
<div ng-if="::(user.isOnline && users.length)"></div>
[/javascript]

ng-repeat:

[javascript gutter=”0″]
<div ng-repeat="item in ::user.items"></div>
[/javascript]

ng-options:

[javascript gutter=”0″]
<select ng-options="n.title for n in ::list"></select>
[/javascript]

directive attributes:

[javascript gutter=”0″]
<user-card user="::currentUser"></user-card>
[/javascript]
it will work even if you have two-way binging inside your directive

 

Disable chrome profile button does not work anymore

In previous chrome version it was very convenient profile switcher: it’s only 2 clicks and you are there. But they decided to update it, why? Now you have this ugly button:

not convenient profile button

instead of icon. And with this button I’ll have dropdown, then model, then…

Before it was possible to switch off this new “feature” in chrome://flags, but with new version off chrome it’s not possible anymore.

But it’s still possible to run browser with this flag (thx for @zerkms for the hint):

[shell]
–disable-new-avatar-menu
[/shell]

So I’ve created AppleScript with shell command to to run chrome with that flag:

[shell]
do shell script "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome –disable-new-avatar-menu &
killall ChromeScript.app"
[/shell]

saved it as an application and added to startup apps list. And now I’m happy again :)

The mac chrome-runner application is on github.

AngularJS: How to pass a method into an isolated scope

I came to conclusion that it’s not very obvious how to pass a method into an isolated scope. And that’s why my junior AngularJS developers just do direct call:

[javascript]
$scope.$parent.methodOfParentScope();
[/javascript]

but it’s more like a hack. It’s more correct to pass it via attribute:

Continue reading

Load remote script from your userscript extension

Just not to lose snippet/solution that I’d been looking for quite some time paste it here:

[javascript]
var load,execute,loadAndExecute;load=function(a,b,c){var d;d=document.createElement("script"),d.setAttribute("src",a),b!=null&&d.addEventListener("load",b),c!=null&&d.addEventListener("error",c),document.body.appendChild(d);return d},execute=function(a){var b,c;typeof a=="function"?b="("+a+")();":b=a,c=document.createElement("script"),c.textContent=b,document.body.appendChild(c);return c},loadAndExecute=function(a,b){return load(a,function(){return execute(b)})};
[/javascript]

and example (loading jQuery):

[javascript]
loadAndExecute("//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", function() {
$("#answer-6825715").css("border", ".5em solid black");
});
[/javascript]

taken from stackoverflow.

Remove some URLs from Chrome autocomplete history

Sometimes misprint could lead to problems with your location bar autocomplete (it will suggest you wrong varian first). For example you accidentally visited gist.gihub.com (note the missing t), and now that URL auto completes each time you start typing gist.….

chrome history autocomplete remove

It’s really annoying.  How can we remove this URL? In case if we don’t want to remove everything, just exact URL.

I found really nice answer here. All you need – just select the URL and press [Shift] + [Delete]. (for Mac is [Fn] + [Shift] + [Delete]).