javascript - addition in angular js -
i'm new angular.js , have simple question. trying make calculator takes input , adds input value total. however, scope.add function not work. below code. appreciated.
html code:
<div class="card"> <div class="item item-text-wrap" style="font-size: 35px; text-align: right"> {{result}} total </div> </div> <div class="padding"> <label class="item item-input"> <input class="input-label" placeholder="add" type="tel" ng-model="t" style="font-size: 35px; text-align: right"> calories </label> </div> <div class="row"> <button class="button ion-refresh button-balanced col" ng-click="reset()" style="font-size: 40px"></button> <button class="button ion-plus-round button-calm col" ng-click="add(t)" style="font-size: 40px"></button> </div>
controller.js
angular.module('calorific.controllers', []) .controller('calcctrl', function($scope) { $scope.result = 0; $scope.reset = function() { $scope.result = 0; }; $scope.add = function(i) { $scope.result = result + i; return result; }; });
use angular.controller()
instead of .controller.
you should instantiate angular.module()
. didn't forget it?
result should passed integer not string, can't take in quote.
i can't see ng-app
, ng-controller
directives. did paste whole code?
Comments
Post a Comment