这是我第一次尝试使用基本的角度应用程序,它会在制表时计算提示。这是我制作的js小提琴。 http://jsfiddle.net/xLc6h7w3/我遇到了一个问题,即它没有看到点击并抛出错误。我不知道我在哪里错了。
angular.module('tipApp',[]).controller('tipController', function() {
var tipCalc = this;
tipCalc.bill = "100";
tipCalc.percent = "10";
tipCalc.calc = function() {
var getme = tipCalc.bill / tipCalc.percent;
var total = getme + tipCalc.bill;
tipCalc.results = total;
};
});
这是html
<h2>Tip Calculator</h2>
<div ng-controller="tipController as tipCalc">
<span>Percent <input class="percent" ng-model="tipCalc.percent" placeholder="Percent Tip" type="input"/>% of
<input class="bill" ng-model="tipCalc.bill" Placeholder="Bill Amount" type="input" /> Bill</span>
<br/><br/>
<input class="btn-primary" type="submit" value="Tabulate" ng-click="tipCalc.calc()"/>
<br/><br/>
<h3>Money Needed with Tip</h3>
<input class="moneyNeeded" type="input" ng-model="results" />
</div>