1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

c# angularjs assistance

Discussion in 'Programming & Webmastering' started by ste2425, Aug 12, 2013.

  1. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,434 (1.47/day)
    Thanks Received:
    383
    Location:
    Huddersfield, uk
    Hi all

    Im doing some work in angularJS. Ive setup a web service which pulls and manipulates data from a database and angularjs is accessing the web service it through the url. Depending on the url the web service returns different data which is then displayed in various ways. This all works grand on a one off loading of the web page. However the data in the database and thus will be displayed will change without any interaction from this page. So i need angularJS to periodically call the urls. I can easily perform the logic afterwards to handle the data returned and checking if its changed etc. I just cannot for the life of me figure out how to call the service and make it reuturn data from the web service when i want it too.

    CONTROLLER
    Code:
    app.controller('mainCtrl', function ($scope, TeamCityService) {
       
            TeamCityService.getDevBuildData(1).then(function (result) {
                $scope.DevToday = result.data.average;
                images(result.data.average, true, 1, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(2).then(function (result) {
                $scope.DevCurrent = result.data.average;
                images(result.data.average, true, 2, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(3).then(function (result) {
                $scope.DevWeek = result.data.average;
                images(result.data.average, true, 3, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(4).then(function (result) {
                $scope.PrivateToday = result.data.average;
                images(result.data.average, false, 1, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(5).then(function (result) {
                $scope.PrivateCurrent = result.data.average;
                images(result.data.average, false, 2, result.data.buildNo, result.data.queavgerage);
            });
            
          
                TeamCityService.getDevBuildData(6).then(function (result) {
                    $scope.PrivateWeek = result.data.average;
                    images(result.data.average, false, 3, result.data.buildNo, result.data.queavgerage);
                });
          
    
    });
    ive got the .factory in a seperate file if youd like that linked too
    thanks all
     
  2. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,434 (1.47/day)
    Thanks Received:
    383
    Location:
    Huddersfield, uk
    ignore that i think ive done it.

    Yup managed it. Im still working out why this time it worked im certain i tried this idea. But ive done that much googleing and trying different ideas i could have easily missed it. Sorry for the wasted post.

    For anyone else who comes accross this looking for the same solution i did.

    Code:
    app.controller('mainCtrl', function ($scope, TeamCityService) {
        getstuff();
        function getstuff() {
            TeamCityService.getDevBuildData(1).then(function (result) {
                $scope.DevToday = result.data.average;
                images(result.data.average, true, 1, result.data.buildNo, result.data.queavgerage);
            });
           
            TeamCityService.getDevBuildData(2).then(function (result) {
                $scope.DevCurrent = result.data.average;
                images(result.data.average, true, 2, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(3).then(function (result) {
                $scope.DevWeek = result.data.average;
                images(result.data.average, true, 3, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(4).then(function (result) {
                $scope.PrivateToday = result.data.average;
                images(result.data.average, false, 1, result.data.buildNo, result.data.queavgerage);
            });
    
            TeamCityService.getDevBuildData(5).then(function (result) {
                $scope.PrivateCurrent = result.data.average;
                images(result.data.average, false, 2, result.data.buildNo, result.data.queavgerage);
            });
            
          
                TeamCityService.getDevBuildData(6).then(function (result) {
                    $scope.PrivateWeek = result.data.average;
                    images(result.data.average, false, 3, result.data.buildNo, result.data.queavgerage);
                });
                setTimeout(getstuff, 4000);
                console.log(1);
            }
    Most likely not the best solution but it works. I cannot believe how simple it is compared to how long it took me to think of trying it :shadedshu

    EDIT:

    Awwwdam i realised why it didnt work when i first tried it. When i called the function from the setTimeout object i added the brackets causing it to go a little berserk.
     
    Last edited: Aug 12, 2013

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page