<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test</title> <script src="js/angular.js"></script> <script type="application/javascript"> (function(angular) { 'use strict'; angular.module('myApp', []) .controller('firstController', function firstController() { this.firstNum = 1; this.secondNum = 1; this.doSum111 = function(){ return this.firstNum+this.secondNum; }; }); })(window.angular); </script> </head> <body > <div ng-app="myApp"> <div ng-controller="firstController as fc"><!--Controller As語法,簡單說就是可以在Controller中使用this來替代$scope fc就相當於this了--> <input type="number" name="firstNum" ng-model="fc.firstNum" required/> +<input type="number" name="secondNum" ng-model="fc.secondNum" required/> ={{fc.doSum111()}} </div> </div> </body> </html>
Cordova學習筆記 中controller的使用及controller as的使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.