0

所以我刚刚开始使用Angular Js,并且已经掌握了很多基础知识。在angular.js中创建一个新服务来将我的本地存储模型数据发送到总线?

所以我有一个表单,我将用户输入的值存储到localstorage。

这部分是好的,但我需要重新创建一个新的服务,以我的数据发送给我的同事写了一些.NET代码...

<script type="text/javascript"> 
    $(function() { 
     var applicationHub = $.connection.applicationHub; 

     var quoteHub = $.connection.quoteHub; 

     var writeShizzles = function(message) { 
      $("body").append("<p>" + message + "</p>"); 
     }; 


     applicationHub.client.applicationCreated = function(message) { 
      writeShizzles(message); 
     }; 

     // noddy app would come from user data obs! 
     var noddyApp = { 
      primaryApplicant: { 
       "firstName": "shizzles", 
       "lastName": "lastShizzles", 
       "emailAddress": "[email protected]", 
       "telephoneNumber": "09986576576" 
      }, 
      otherApplicants: [], 
      company: { 
       "monthlyCardTakings": 50000.01, 
       "sector": 1, 
       "monthsInBusiness": 24, 
       "tradingName": "tradingNameba5f7837-0438-4025-beb1-2324d4f972ff", 
       "postcode": "postcodea84d3ce0-9281-4b6c-a5d5-64bb74e66bca" 
      }, 
      "tracking": {} 
     }; 

     // Start the connection. 
     $.connection.hub.start().done(function() { 
      applicationHub.server.createApplication(noddyApp) 
       .done(function(result) { 
        writeShizzles("Created App with Id: " + result); 

        applicationHub.server.createAdvance({ 
         "applicationId": result, 
         "amount": 50000.10, 
         "cardPercentage": 0.31, 
         "totalRepayment": 55000.60 
        }); 
       }); 

      quoteHub.server.getAdvanceLimits() 
       .done(function (result) { 
        writeShizzles("AdvanceLimits: " + JSON.stringify(result)); 
       }); 

      quoteHub.server.getMaxAdvanceMatrix() 
       .done(function (result) { 
        writeShizzles("AdvanceMatrix: " + JSON.stringify(result)); 
       }); 
     }); 
    }); 
</script> 

任何人都可以在这方面帮助或点我请正确的方向。

在此先感谢

GUIDeveloper

+0

看看这个https://docs.angularjs.org/api/ng/service/$ http。您需要创建一项服务来发送和接收来自Web服务的数据 – SerhatCan

+0

您的具体问题是什么? –

+0

感谢您的快速响应我现在看看 – GUIDeveloper

回答

0

行,所以我排序这将只是在我的控制器创建我的连接的可变

var applicationHub = $.connection.applicationHub; 

再创建一个函数来传递我所有的数据存储在本地存储到集线器

$scope.createApp = function() { 
    var customerApplication = { 
     primaryApplicant: { 
      "firstName": $localStorage.firstName, 
      "lastName": $localStorage.lastName, 
      "emailAddress": $localStorage.emailAddress, 
      "telephoneNumber": $localStorage.telephoneNumber, 
      "offersCheck": $localStorage.offersCheck, 
      "offers2Check": $localStorage.worldpayCheck 
     }, 
     otherApplicants: [], 
     "tracking": { 
      "googleAnalyitics": { 
       UtmSource: $localStorage.utmSource, 
       UtmMedium: $localStorage.utmMedium, 
       UtmCampaign: $localStorage.utmCampaign, 
       UtmTerm: $localStorage.utmTerm, 
       utmContent: $localStorage.utmContent 
      } 
     } 
    }; 

    $.connection.hub.start().done(function() { 
     applicationHub.server.createApplication(customerApplication) 
      .done(function (result) { 
       $localStorage.applicationId = result; 
      }); 
    });  
}; 
相关问题