Skip to content

Instantly share code, notes, and snippets.

@khoand0000
khoand0000 / different-a-button.md
Last active December 14, 2015 10:55
Different between <a> and <button> button, ng-click & ui-sref
  • Same: use class="button"
  • Always try to using ui-sref first, just using ng-click if need to do something (not moving state) or change states dynamic (ui-sref doesn't support it)
  • Different:
<a> <button>
change state/url use ui-sref="" (no need create more functions, short code if just change state/url and not more complex code) or ng-click="changeUrl()" (use same <button>) only way using ng-click="changeUrl()" with $scope.changeUrl = function() { $state.go('tab.posts', {postId: postId});}
use ng-click no effect having effect. side effect: submit form automatically
@khoand0000
khoand0000 / avoid-slashes-when-saving.md
Last active August 29, 2015 14:25
note when saving data from $_POST in wordpress (wp_magic_quotes).

Because wordpress call wp_magic_quotes() to add slashes before we use $_POST or $_GET ($_REQUEST), so if you save data from $_POST or $_GET ($_REQUEST) in wordpress,

  • single value, do
$username = stripslashes($_POST['username'])
  • or all of values, do
$_POST = stripslashes_deep($_POST);
@khoand0000
khoand0000 / ng-model.md
Last active August 29, 2015 14:25
Get values (javascript code) from view
  • You want to create a login form, you need get username & password from html inputs when user click login button, code should like that
<!-- html code, view-->
<div class="list">
    <label class="item item-input">
        <input type="text" placeholder="Username" ng-model="user.username">
    </label>
    <label class="item item-input">
        <input type="password" placeholder="Password" ng-model="user.password">
@khoand0000
khoand0000 / html-text.md
Last active August 29, 2015 14:25
Output html text in angularjs
$scope.content = "<b>bold</b> text";
  • With
<div>{{content}}</div>

will output text content

For the visual learners like myself....

this:

<div ng-messages="requestForm.email.$error" ng-messages-include="form-messages"></div>

now needs to be:

@khoand0000
khoand0000 / ion-nav-bar.md
Last active August 29, 2015 14:25
Notice when using <ion-nav-bar>
  • <ion-nav-title> should be used in although duplicate, don't include it in <ion-nav-bar> (special case: title of <ion-nav-bar> is static, mean that no view-title attributes in all <ion-view>)
  • same for ``
@khoand0000
khoand0000 / length_md5_sha.md
Created July 28, 2015 20:10
length of md5, sha*
ALgorithm Length (bytes, characters)
MD5 32
SHA1 40
SHA256 64
SHA512 128
@khoand0000
khoand0000 / directive.md
Last active August 29, 2015 14:26
Relation with compile (pre, post), controller, link when defining directive
  • compile is used for transforming template, link is used after template is cloned
  • If compile is existing, link is not effect (be not called)
    • If compile return object, order of functions are called: compile > controller > pre > post
    • If compile return function (post-link), is equivalent to link function, order of functions are called: compile > controller > post
  • If compile is ommitted, controller &gt; link
@khoand0000
khoand0000 / angular-cookies-ionic.md
Last active August 29, 2015 14:26
Notice when using angular-cookies with ionic
  • When you use bower install angular-translate-storage-local (remember chosen language) for angular-translate with ionic (current version 1.0.1), it will install latest angular-cookies (current is 1.4) also, but ionic is using angularjs 1.3.13, so error is:
Uncaught Error: [$injector:unpr] Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies <- $cookieStore <- $translateCookieStorage <- $translateLocalStorage <- $translate <- $cookies
  • To solve the problem, you must use angular-cookies corresponds to angularjs which ionic is using, mean angularjs 1.3.13. So use the bower command: bower install angular-cookies#1.3.13 after bower install angular-translate-storage-local
@khoand0000
khoand0000 / view_event.md
Last active August 29, 2015 14:26
order view events

$stateChangeStart > $stateChangeSuccess > controller is loaded > $ionicView.beforeEnter > $ionicView.enter > $ionicView.afterEnter