Web(三)--angularjs
2629 ワード
次のファイルは同じディレクトリの下にあります.
myTodoApp.jsmyTodoCtrl.jsindex.pyangularjs_test.html
index.pyの内容:
angularjs_test.htmlの内容:
myTodoCtrl.jsの内容
に合格http://localhost/angularjs_testアクセス
myTodoApp.jsmyTodoCtrl.jsindex.pyangularjs_test.html
index.pyの内容:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world, this is tornado test!")
class StoryHandler(tornado.web.RequestHandler):
def get(self, story_id):
self.write("You requested the story " + story_id)
class TemplateHandler(tornado.web.RequestHandler):
def get(self):
items = ["Item 1", "Item 2", "Item 3"]
self.render("template.html", title="My title", items=items)
class AngularjsTestHandler(tornado.web.RequestHandler):
def get(self):
self.render("angularjs_test.html")
application = tornado.web.Application([
(r"/", MainHandler),
(r"/index.py", MainHandler),
#(r"/story/([0-9]+)", StoryHandler),
(r"/template", TemplateHandler),
(r"/index.py/template", TemplateHandler),
(r"/index.py/angularjs_test", AngularjsTestHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
angularjs_test.htmlの内容:
<!DOCTYPE html>
<html>
<body>
<div ng-app="myTodoApp" ng-controller="myTodoCtrl">
<h2> </h2>
<p><textarea ng-model="message" cols="40" rows="10"></textarea></p>
<p>
<button ng-click="save()"> </button>
<button ng-click="clear()"> </button>
</p>
<p> : <span ng-bind="left()"></span></p>
</div>
<script src="//www.w3cschool.cc/try/angularjs/1.2.5/angular.min.js"></script>
<script src="myTodoApp.js"></script>
<script src="myTodoCtrl.js"></script>
</body>
</html>
myTodoApp.js
var app = angular.module("myTodoApp", []);
myTodoCtrl.jsの内容
app.controller("myTodoCtrl", function($scope) {
$scope.message = "";
$scope.left = function() {return 100 - $scope.message.length;};
$scope.clear = function() {$scope.message="";};
$scope.save = function() {$scope.message="";};
});
に合格http://localhost/angularjs_testアクセス