web(三)--angularjs

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   sp   檔案   on   div   

下面的檔案在同一目錄下.

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="//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訪問即可

web(三)--angularjs

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.