how to compare a stringvalue in ng-show inside a customdirective?

angularjs, angularjs-directive, angularjs-ng-repeat

Solution

The expression

ng-show="name.status_p1==working"

compares `name.status_p1` with a `working` property on the current scope, which is not defined in your case. What you need is to compare it with the literal string `'working'`.

ng-show="name.status_p1=='working'";

Modified Plunkr

Problem

Trying to use a directive with an ng-show statement in it. Basically it checks against the value of a string which is the status_p1 property in my 'names' jsonarray: ``` ng-show="name.status_p1==working" ``` The directive is defined as this: ``` app.directive('radioButton',function(){ return { restrict: 'E', replace: 'true', template: '<table border="2px">' + '<tr><td>{{name.name}}</td><td>Working</td><td><img src="http://www.iconshock.com/img_jpg/REALVISTA/general/jpg/256/cross_icon.jpg" alt="img1" id="imgworking" ng-show="name.status_p1!=working"><img src="http://png-1.findicons.com/files/icons/2198/dark_glass/128/camera_test.png" alt="img2" ng-show="name.status_p1==working"></td></tr>' + '</table>' }; }) ``` The controller+ namesarray in my main page looks like this: ``` app.controller('MainCtrl', function($scope) { $scope.names = [ { name: 'couple 1', status_p1: 'working', status_p2: 'retired' } ] }); ``` And finally the main page: ``` <body ng-controller="MainCtrl"> <div ng-repeat="name in names"> <radio-button></radio-button> </div> </body> ``` Currently is displays a cross where it should be displaying a check/tick. I was expecting the condition to evaluate to TRUE because the status_p1 property equals 'working'. How can I modify this ng-showstatement to make the string comparison working? plunkr link:http://plnkr.co/edit/3VdsbsSHpkNJFVnvkmOW?p=preview

Original source