0

I am trying to populate a textaread with a variable which i have parsed from a file. textarea gets data from a controller when popup is called. This controller gets data from another controller which has parsed the data. But it gives error on injecting. Please help.

Steps to reproduce the behaviour 1. I have a viewXML controller ///Creating controller for ViewXML - Data will be displayed in text area

angular.module('fbsiperf').controller('ViewXMLCtrl', ['$scope','successcount',function($scope,successcount) {
$scope.successcount=successcount;
$scope.cancel = function() {
       $scope.$dismiss();
}
}])

2. It gets data from below function

angular.module('fbsiperf').controller('zScriptResultsCtrl', [ '$scope', '$http', '$state', '$stateParams', '$uibModal', 'Upload', function($scope, $http, $state, $stateParams, $uibModal, Upload) {
    var rowRendered = 0;
    init(); 
    function init() {
        /** *******method list: get Data *************** */
        $http.get("/xml/getResults").success(function(data, status) {
            $scope.results = data;
            $scope.totalScripts = data.length;
            var success = 0;
            var fail = 0;
            $scope.symbolicViewList = [];
            $scope.mauiViewList = [];
            $.each($scope.results, function(index, element) {
                if (element.result != null && element.result == "Passed") {
                    success++;
                } else {
                    fail++;

            });
            $scope.successCount = success;
            $scope.failCount = fail;

        });
    }
    var symbolicViewSearch = null;
    var mauiViewSearch = null;
    var prodCodeSearch = null;
    var zscriptResultDefs = [
        {
            headerName : "View XML",
            field : "viewXML",
            width : 150,
            unSortIcon : true,
            cellRenderer : function(params) {
                return "<a ng-click=\"viewXML()\">XML</a>";}

            },{
        headerName : "MAUI View",
        field : "mauiView",
        width : 150,
        unSortIcon : true,
        filter : 'text'
    }


    // View XML
    $scope.viewXML = function() {
        //if(null != $scope.ticket && "" != $scope.ticket) {
        if(true) {
            //open modal for adding data
            var modalInstance = $uibModal.open({
                templateUrl : '../../views/templates/viewXML.html',
                controller : 'ViewXMLCtrl',
                windowClass : 'center-modal',
                backdrop : 'static',
                keyboard : false,
                size : 'lg',
                resolve : {
                    successcount : function() {
                        console.log($scope);
                        console.log($scope.successCount);
                            return $scope.successCount;
                        //return "Name";
                    }
                }
            });
        } else {
            alert("No CM# found")
        }
    }

3. i am displaying it in html here

<textarea rows="4" cols="50" ng-model="successcount"></textarea>

instead of populating the text box i get error as

[$injector:unpr] Unknown provider: successcountProvider <- successcount <- ViewXMLCtrl

  • Can you post the successcount provider declaration here? – FakirTrappedInCode Jan 24 '19 at 16:42
  • i updated the code with complete snippet – Avinash billore Jan 24 '19 at 17:10
  • I see two controllers yet no providers. Where is 'successcount' defined? Are you trying to access $scope.successcount from the 'zScriptResultsCtrl' controller in the 'ViewXMLCtrl'? You can't do it that way. Create a factory or service and inject it into both controllers. That way you can share data between each one. – Mickers Jan 24 '19 at 17:15
  • Read this https://stackoverflow.com/questions/27356299/global-communication-in-angular-module-event-bus-or-mediator-pattern-service and this may give you some ways to achieve what you would want to do if you are told not to use $rootScope.$broadcast('successcount') – FakirTrappedInCode Jan 24 '19 at 17:23
  • Thank you for the pointers, looks like i do need a service. Let me try that way and i will share if i am able to do it successfully. – Avinash billore Jan 24 '19 at 18:11

0 Answers0