首页 > 代码库 > web(三)--angularjs
web(三)--angularjs
下面的文件在同一目录下.
myTodoApp.js
myTodoCtrl.js
index.py
angularjs_test.html
index.py中内容:
import tornado.ioloopimport tornado.webclass 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="http://www.w3cschool.cc/try/angularjs/1.2.5/angular.min.js"></script><script src="http://www.mamicode.com/myTodoApp.js"></script><script src="http://www.mamicode.com/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访问即可
web(三)--angularjs
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。