1

Yeah, This is weird issue.

I am adding code to existing code base where there is a directive

<my-progress ng-progress="processingReport" msg="someString"></my-progress>

The problem is that msg needs to be dereferenced string.

I have a scope variable as $scope.myStatus but providing msg={{myStatus}} is not producing anything

Is there a way to dereference the value of $scope.myStatus so that msg only receives its value?

UPDATE

The directive looks like

.directive('myProgress', function($compile) {
      return {
        restrict: 'E',
        link: function(scope, element, attrs){
          var msg = attrs.msg?attrs.msg: "{{"+attrs.ngMsg+"}}";
            var template = '<p ng-if="'+ attrs.ngProgress +'"><img src="img/busy-20.gif" alt=""> '+ msg +'</p>';
            var el = $compile(template)(scope);
            element.replaceWith(el);
          }
      };
    })

UPDATE 1
As per @charlietfl recommendation, the following worked well

In Controller

$scope.runningStatus = {progressStatus: 'Not Started'};

In HTML

<my-progress ng-progress="processingReport" ng-msg="runningStatus.progressStatus"></my-progress> 
1
  • Can you post the code of the myProgress directive? It depends on the type of binding. Commented May 7, 2015 at 1:19

2 Answers 2

1

Based on directive code you should be able to use :

ng-msg="myStatus"

Which would get added into the template as an expression

Note the line in directive:

var msg = attrs.msg?attrs.msg: "{{"+attrs.ngMsg+"}}";

which looks for one or the other attribute and treats them differently

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

4 Comments

That works, just that the value is passed just once, if value for myStatus changes, it is never updated on the screen. I do not know how to solve this
try making your scope model an object with a property myStatus .... $scope.someObj={myStatus:'som value'} then ng-msg="someObj.myStatus"
Not sure if I followed you, but the way it looks is ` $scope.updateStatus = function(responsePayload) { var text = responsePayload.result['reportStatus']; $scope.progressStatus = text; . This is the first time $scope.progressStatus` is used
always best to use objects on scope when you can ..instead of primitives
1

The directive is kind of a hack and should be rewritten, but as is it should accept an interpolated expression:

<my-progress ng-progress="processingReport" msg="{{myStatus}}"></my-progress>

Don't forget the double quotes " around {{myStatus}}

If it still doesn't work, could you test that your scope is okay by adding this test element just after the directive one:

<div>{{myStatus}}</div>

1 Comment

That works, just that the value is passed just once, if value for myStatus changes, it is never updated on the screen. I do not know how to solve this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.