??????Angular???????????
???????????? ???????[ 2015/8/28 13:56:03 ] ?????????????????? ????
?????????е?????????????Service
???????Web??????????????????????Щ??????????? ???????????????????Щ?????????? ???????????? ???????? ??Щ????????????????? ???????????????????????????????????????? ??????????????????е?????Щ????.?????????ζ?????????????????????????????Щ???? ????????????????????????????? ?????Щ???????????????????????е?? ?????????????????????μ?? ???????????????????Щ??????????????????????.??????????????????Щ??????????????????????????? ????????????????serviceLoadedFromExternal?? ?????????API????makeServiceCall?? ????????????API?? ?????????к???????????????????(????????????????????????????????)?? ??????????????????????????angular service?? ???????????????????????滻?????mock???? ?????????mock???????????????????????.???????????δ???:
???????????????????
????angular.module(“TheNG”?? [])
????.controller(“AController”?? function ($scope) {
????$scope.someAction = function () {
????// handle some logic here
????serviceLoadedFromExternal.makeServiceCall();
????};
????});
??????÷????service???????????
????angular.module(“TheNG”?? [])
????.factory(“wrappedService”?? function () {
????return {
????makeServiceCall: function () {
????serviceLoadedFromExternal.makeServiceCall();
????}
????};
????})
????.controller(“AController”?? function ($scope?? wrappedService) {
????$scope.someAction = function () {
????// handle some logic here
????wrappedService.makeServiceCall();
????};
????});
????Angular??????黯??? ????????????????????????JS?????????????? ?????????????????????? ???????Spring IOC???? ???????????????????????????滻??? ?????????????????????.
??????????Ajax??????service?????
????Angular?????service???????Щ????????????? ??????? ??????????service???????????????????????????? ???? ????????Ajax???????????service?????????.
?????????????????????????directive????controller?????$http?? ?????????????????????. ?????$http??????????????????? ??????????????????????????? ??????????????????????http???? ????????о???????Spring MVC??request method????????HttpServeletRequest????? ?е????? ?????????????????? ?????Щ???????????????????. ????????????????鷳?? ??????ò????$httpBackend????????HTTP????????.
????????????跨?ò?????????????Ajax????????service?У? ???????????mock??service??????????????????????. ???????????????д????? ???????????????????????? ??mock$http??????????? ??????????????????.
???????Promise????Ajax???????? ???????????????
????Angular?????е?Ajax???????????????Promise???? ?????齫????Ajax??????????????????????????????????http?????service?? ????????????service???????÷????promise????????????δ???.
???????????????????????????????:
????angular.module(“TheNG”?? [])
????.service(“deliveryService”?? function ($http) {
????this.validateAddress = function (address?? success?? failure) {
????$http.post(‘/unknown’?? address).then(success?? failure);
????};
????})
????.controller(“DeliveryController”?? function ($scope?? deliveryService) {
????var acceptAddress = function () {
????console.log(‘address accepted’);
????};
????var rejectAddress = function () {
????console.log(‘address rejected’);
????};
????$scope.validateAddress = function () {
????deliveryService.validateAddress($scope.address?? acceptAddress?? rejectAddress);
????};
????});
????????????????????????????????????????????????deliveryService?? ??????????????????????? ????????????????. ????д??????????????? ??????????????????
????????? ??????service?????validateAddress?????????????????????? ??????????????????????????? ????????????????????? ??????????a???????????????????? ?????????????????????? ???????????????????????????????.
?????????????μ??????????????????????????? ???????? ??????service??????????????????????/???????? ????????service mock??? ?????mocked service??????????????????????????????????????????.???????????????????? ????????deliveryService??validateAddress()????mock??? ????????????а?????acceptAddress()??rejectAddress()????????!
????????? ??????????????????service?е?API????? ????????????????????API????????? ??????????????????service????????????HTTP???? ??????????????е?.
?????????????????? ????????? ??????????????д????. ????????????????????: service??API????????promise?? ????????????????????????promise??? ????????????mock???service?????????????????????????promise?? ??????promise?????????????????????:
????angular.module(“TheNG”?? [])
????.service(“deliveryService”?? function ($http) {
????this.validateAddress = function (address) {
????return $http.post(‘/unknown’?? address);
????};
????})
????.controller(“DeliveryController”?? function ($scope?? deliveryService) {
????var acceptAddress = function () {
????console.log(‘address accepted’);
????};
????var rejectAddress = function () {
????console.log(‘address rejected’);
????};
????$scope.validateAddress = function () {
????deliveryService.validateAddress($scope.address).then(acceptAddress?? rejectAddress);
????};
????});
????????????????????????Angular???????????????????? д??д??????е????? ?????????.
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??γ????????????????????????????????????漰??Щ???????????????????????????????????????????????????????????????е???????????????????????????????????????Щ??????????????????????Ч?????????????????????????????????????α?????????????????????????????????????????????????????????????????????????????????????????????????????????????????γ?????????????????????????????ζ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????