Last active
December 17, 2015 00:59
-
-
Save sinmetal/5525243 to your computer and use it in GitHub Desktop.
AngularJSがDOMを生成したことを検知する方法を考える。
directive作って、function postLinkを設定してやれば、DOMが生成された時に、呼んでくれるみたいだ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja" ng-app="myApp"> | |
<head> | |
<meta charset="utf-8"> | |
<title>sample</title> | |
<link rel="stylesheet" href="../static/stylesheets/bootstrap.min.css"> | |
<link rel="stylesheet" href="../static/stylesheets/bootstrapSwitch.css"> | |
</head> | |
<body> | |
<div class="row-fluid" ng-controller="mainCtrl"> | |
<div class="span12"> | |
<div class="bs-docs-example" ng-repeat="item in items"> | |
{{item}} | |
<div class="switch" bs-switch> | |
<input type="checkbox" checked /> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
<script src="../static/js/bootstrap.min.js"></script> | |
<script src="../static/js/bootstrapSwitch.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> | |
<script> | |
angular.module('myApp', []) | |
.directive('bsSwitch', function factory() { | |
return function postLink(scope, iElement, iAttrs) { | |
iElement['bootstrapSwitch'](); | |
}; | |
}); | |
var mainCtrl = function($scope) { | |
$scope.items = ["Hoge", "Fuga"]; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment