What if you pass your controller's $scope as a parameter of your 
showMessage function. That way the factory method would look like this:

function showMessage(localScope, message) {
      localScope.message = message;
      localScope.data = {
        showMessage: true
      };
   }

And in you controller you would call it: commonFactory.showMessage($scope, 
message);

On Monday, June 22, 2015 at 5:31:57 AM UTC-7, Yogesh N wrote:
>
> angular.module('accguru')
>  .controller('salesOrderController', function ($scope, $state, $filter, 
> databasefactory, commonFactory) {
>
>    var tenantId = metaDataLocalStorage.getTenantId();
>    var branchId = metaDataLocalStorage.getBranchId();
>    var taxCategoryFetchQuery = commonFactory.getTaxCategoryFetchQuery(
> tenantId, branchId);
>
>    var init = function() {
>      getAllSimpleTaxes();
>    };
>
>    init();
>
>    function getAllSimpleTaxes() {
>       databasefactory.retriveData(taxCategoryFetchQuery).then (function (
> results) {
>         $scope.taxes = [];
>         if (results.rows.length > 0) {
>           for (var i = 0; i < results.rows.length; i++) {
>             $scope.taxes.push(results.rows.item(i));
>           }
>         }
>       }, function (errorMsg) {
>         showMessage(errorMsg);
>       });
>    }
>
>    function showMessage(message) {
>       $scope.message = message;
>       $scope.data = {
>         showMessage: true
>       };
>     }
> })
>
> .controller('receiptController',function($scope, $state, $filter, 
> databasefactory, commonFactory) {
>
>    var tenantId = metaDataLocalStorage.getTenantId();
>    var branchId = metaDataLocalStorage.getBranchId();
>
>    var glAcctOrgFetchQuery = 
> commonFactory.getGlAcctOrgFetchQuery(tenantId, branchId);
>
>    var init = function() {
>        getPaymentModeGlAcctOrgList();
>    };
>
>    init();
>
>    function getPaymentModeGlAcctOrgList() {
>       
> databasefactory.retriveData(glAcctOrgFetchQuery).then(function(results) {
>         $scope.paymentModeGlAcctOrgArr = [];
>         if (results.rows.length > 0) {
>           for (var i = 0; i < results.rows.length; i++) {
>             $scope.paymentModeGlAcctOrgArr.push(results.rows.item(i));
>           }
>         }
>       }, function(errorMsg) {
>         showMessage(errorMsg);
>       });
>    }
>
>    function showMessage(message) {
>       $scope.message = message;
>       $scope.data = {
>         showMessage: true
>       };
>    }
> });
>
>
> In the above controller code, i want to move showMessage(message) function 
> to the commonFactory.
> Since i am using $scope, i am not able to move to commonFactory. can 
> anyone please help me out in solving this issue.
>
> Here is the commonFactory code:
>
> angular.module('commonModule')
> .factory('commonFactory', function(queriesTaxCategory, 
> queriesGlAccountOrganization) {
>   var commonFactory = {};
>
>   commonFactory.getTaxCategoryFetchQuery = function(tenantId, branchId) {
>     var taxCategoryFetchQuery = 'SELECT * FROM TaxCategory WHERE tenantId 
> =' + tenantId +
>          ' AND branchId =' + branchId;
>     return taxCategoryFetchQuery;
>   };
>
>   commonFactory.getGlAcctOrgFetchQuery = function(tenantId, branchId) {
>     var glAcctOrgFetchQuery = 'SELECT * FROM GlAccountOrganization WHERE 
> tenantId =' + tenantId +
>     ' AND branchId =' + branchId;
>     return glAcctOrgFetchQuery;
>   };
>   return commonFactory;
> });
>
> Here is the html code, where i am displaying error message if 
> data.showMessage is true.
>
> <ion-view title="New Receipt">
>   <div class="bar bar-loading bar-assertive" ng-if="data.showMessage">
>      {{message}}
>   </div>
>
>   <ion-content>
>     <div>
>     ------
>     -----
>     -----
>     <div>
>   </ion-content> 
> </ion-view>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to