Skip to content

Instantly share code, notes, and snippets.

@comilab
Last active December 21, 2015 15:29
Show Gist options
  • Save comilab/6326947 to your computer and use it in GitHub Desktop.
Save comilab/6326947 to your computer and use it in GitHub Desktop.
AngularJSでTwitterもどきを作る
<!DOCTYPE html>
<html lang="ja">
<head>
<title>Twitterもどき</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body ng-app ng-init="tweets = []; t='';">
<form name="tweetForm">
<textarea required="required" name="t" ng-model="t" ng-maxlength="140"></textarea>
<span>{{t.length}} / 140</span>
<ul class="errors" ng-show="tweetForm.$valid">
<li ng-show="tweetForm.t.$error.required">Required!</li>
<li ng-show="tweetForm.t.$error.maxlength">Too long!</li>
</ul>
<button type="button" ng-click="tweets.push(t)" ng-disabled="tweetForm.$invalid">tweet</button>
</form>
<article ng-repeat="tweet in tweets">{{tweet}}</article>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment