DRYな備忘録

Don't Repeat Yourself.

angularjs

angularjsのviewでencodeURIComponentしたい

問題 angularのViewで(not controller)華麗にencodeURIComponentとかしたいじゃないですか、こんな感じで <a href="/tasks/{{task.id | encodeURIComponent}}">{{task.name}}</a> filterをカスタマイズしよう angular.module('myapp', []).filter("encodeURIComponent", function() { return window.encodeURIComp…

JavaScriptでお手軽in_array

なんかスコープとかの問題でunderscoreとか使えないとき、でゴルフっぽいコード書きたいとき [0,1,2,3].indexOf(3) > -1; // true [0,1,2,3].indexOf(100) > -1; // false angularのdirectiveの中とか <div data-ng-if="[0, 2, 3].indexOf(player.type) > -1"> アクセサリ一覧: </div> みたいな DRY

たぶん世界一簡単なAngularJSのサンプル

index.html <html> <head> <meta charset="utf-8" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script> <script type="text/javascript" src="main.js"></script> </head> <body data-ng-app="foo"> <div data-ng-controller="BarController"> </div></body></html>

AngularJSでBootstrapのModalを出す方法メモ

問題 AngularJSと、Bootstrapのui.bootstrap使ってて BootstrapのModal機能とか使いたくなるけれど Angular的なControllerや$scopeの扱いが混乱したのでメモ 参考 公式: Angular directives for Bootstrap サンプル 親View。対応するControllerのメソッドを…