Created
December 3, 2013 15:23
-
-
Save do-aki/7771047 to your computer and use it in GitHub Desktop.
AngularJS の練習。 タグ的なものを入力する感じのモノ。
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 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