Skip to content

Instantly share code, notes, and snippets.

@do-aki
Created December 3, 2013 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save do-aki/7771047 to your computer and use it in GitHub Desktop.
Save do-aki/7771047 to your computer and use it in GitHub Desktop.
AngularJS の練習。 タグ的なものを入力する感じのモノ。
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.3/angular-animate.min.js"></script>
<script>
function ctrl($scope) {
$scope.words = [];
$scope.input = function() {
$scope.words = $scope.title.split(/[ ,]/);
};
$scope.remove = function() {
var remove_word = this.word;
$scope.title = $scope.title.split(/[ ,]/)
.filter(function(v) { return v != remove_word })
.join(',');
$scope.input();
};
}
</script>
<title>{{title}}</title>
</head>
<body ng-controller="ctrl">
<input type="text" ng-model="title" ng-keyup="input()">
<ul>
<li ng-repeat="word in words track by $index" ng-if="word.length">
{{word}} [<a href="#" ng-click="remove()">x</a>]
</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment