2

I am passing three $rootScope from process controller to Rating controller so based on the $rootScope status i am enabling and disabling buttons. Edit and view is working good but on $rootScope === 'NewPrt', Once user answered all question i want to enable submit button on 'NewPrt'.

So far i tried below code..

HTML

<button type="submit" class="btn btn-default" ng-disabled="disabledDraft"  ng-click="savePRTDraft()" ng-show="showSaveDraftBtn">Save
        as Draft</button>
    <button type="submit" class="btn btn-primary"
        ng-disabled="disableSubmitButton" ng-click="submitClicked()">Submit</button>

ProcessCtrl.js

$scope.gotoQstnPage = function(isNew) {
        var qrtUrl = "/createRtgQstnAir/"+$scope.processDTO.processKey + "/"+isNew;
        $rootScope.status = 'NewPrt';
        $location.path(qrtUrl);
    }

$scope.editProcessRating = function(prcsSessionKey) {
            var prtUrl = "/getProcessRating/"+prcsSessionKey;
            $rootScope.status = 'edit';
            $location.path(prtUrl);

        }

        $scope.viewProcessRating = function(prcsSessionKey) {
          var prtUrl = "/getProcessRating/"+prcsSessionKey;
          $rootScope.status = 'view';
          $location.path(prtUrl);
        }

RatingCtrl.js

if(j > $scope.questionnaire.length){
              if($rootScope.status ==='edit') {
                $scope.disableSubmitButton = false;
                $scope.disabledDraft = false;
                $scope.showBusDecDropDown = true;
              }

 $scope.disabledDraft = function(){
        if($rootScope.status === 'view') {
          return true;
        }
        else {
          return false;
        }
      }
      if ($rootScope.status === "NewPrt" ) {
        $scope.disabledDraft = false;
      }

3 Answers 3

1

You can try like this instead of using $rootScope

var app = angular.module('myApp', []);
app.controller('Controller', function ($scope) {

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="Controller">
    <form name="myForm">
        <input name="myText" type="text" ng-model="mytext" required />
        <button ng-disabled="myForm.$invalid">Save</button>
    </form>
</div>

Sign up to request clarification or add additional context in comments.

Comments

1

When both conditions are true, enable the submit button:

if ($rootScope ==='edit' || $rootScope ==='NewPrt') {
    $scope.disableSubmitButton = false;
}

Comments

0

if you want to use $rootScope you need to inject $rootScope in every controller where you want to use config run any where

like this

var app = angular.module('app');
app.config(function($rootScope){
  $rootScope.name = "Hello World"
});

app.controller('home',function($scope,$rootScope){
$scope.name = $rootScope.name;
alert($scope.name) 
})

3 Comments

$rootScope is injected in all controller , based on my code how i can enable disableSubmitButton when $rootScope === 'NewPrt' and questions answered.
$rootScope is object u need to assign property in $rooScope like $rootScope.value = 'NewPrt' then it will easily allow to set condition like if( $rootScope.value === 'NewPrt'){ //enable submit button //its easy }
please check my question i had value assigned it $rootScope.status ==='NewPrt'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.