Enter a number: X2
Result: {{result}}
var mainApp = angular.module("mainApp", []); mainApp.factory('MathService', function() { var factory = {}; factory.multiply = function(a, b) { return a * b } return factory; }); mainApp.service('CalcService', function(MathService){ this.square = function(a) { http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/angularjs/index.jsp Copyright © vietjack.com return MathService.multiply(a,a); } }); mainApp.controller('CalcController', function($scope, CalcService) { $scope.square = function() { $scope.result = CalcService.square($scope.number); } }); Kết Mở trang textAngularJS.jsp trình duyệt web xem kết quả: http://vietjack.com/ Trang chia sẻ học online miễn phí Page ... online miễn phí Page http://vietjack.com /angularjs/ index.jsp Copyright © vietjack.com return MathService.multiply(a,a); } }); mainApp.controller('CalcController', function($scope, CalcService)... mainApp.factory('MathService', function() { var factory = {}; factory.multiply = function(a, b) { return a * b } return factory; }); mainApp .service( 'CalcService', function(MathService){ this.square...http://vietjack.com /angularjs/ index.jsp Copyright © vietjack.com this.square = function(a) { return MathService.multiply(a,a); } }); Ví dụ Dưới ví dụ minh họa cho dẫn bên testAngularJS.jsp