Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • George Phillipson 108 posts 288 karma points
    May 26, 2021 @ 15:28
    George Phillipson
    0

    Pass parameter from angular controller to resource and the api controller

    Hi

    First time I have had to actually build something with angular and I have hit a roadblock, how do I pass a parameter from controller to resource and then api controller.

    I currently have:

    Controller:

    angular.module("umbraco").controller("My.SendNewsLettersController", function ($scope, sendNewsLettersResource, $http) {
    "use strict";
        var vm = this;
        vm.date = "";
    
        vm.config = {
            enableTime: false,
            dateFormat: "d-m-Y ",
            time_24hr: false
        };
    
        vm.datePickerChange = datePickerChange;
        var dateSelected = "";
        function datePickerChange(selectedDates, dateStr, instance) {
            dateSelected = dateStr;
    }
    vm.clickButton = clickButton;
    
    function clickButton() {
        //Pass date from datepicker
        sendNewsLettersResource.newsLetters(dateSelected).then(function(response) {
            alert(response.data);
        });
    }
    

    });

    Then resource

    angular.module("umbraco.resources").factory("sendNewsLettersResource", function($q, $http, umbRequestHelper) {
    return {
        newsLetters: function() {
            return umbRequestHelper.resourcePromise($http.get("backoffice/My/NewsLettersApi/SendNewsLetters/?strDate=" + "pass parameter"), "Failed");
        }
    }
    

    });

    FInally API controller

     public int SendNewsLetters(string strDate){}
    
  • George Phillipson 108 posts 288 karma points
    May 26, 2021 @ 15:49
    George Phillipson
    101

    Figured it out

    angular.module("umbraco.resources").factory("sendNewsLettersResource", function($q, $http, umbRequestHelper) {
    return {
        newsLetters: function (strdate) {
            return $http({
                method: "GET",
                params: {
                    strDate: strdate
                },
                url: "backoffice/My/NewsLettersApi/SendNewsLetters/"
            });
        }
    }
    

    });

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies