0

i want disable image with angular js i used a function to do that i have this error Cannot create property 'type' on string:

Controller :

 $scope.ActivePlaceSpotCAM = function (idPlace, typePlace) {
        var res = null;
        angular.forEach($scope.ListPlaces, function (value, key) {      
            angular.forEach(value.type, function (value ,key) {
                if (value.type = typePlace && value.id == idPlace) {
                    res = value;   
                }

            });
        });
        return res;
    }

html :

<div class="SvgPicto  col-lg-2  col-md-2  col-sm-2  col-xs-2">
                        <img src="@Url.Content("~/Resources/Common/pic.svg")" ng-init="configuredPlaces[@nbPlace] == place.type" ng-if="ActivePlaceSpotCAM(place.id,place.type)"/>
                    </div>
2
  • Have you an idea please Commented Mar 15, 2018 at 10:49
  • You are accidently trying to assign a type variable, guess you want to compare -> (value.type = typePlace && value.id == idPlace) should be (value.type == typePlace && value.id == idPlace) Commented Mar 15, 2018 at 11:22

1 Answer 1

1

You are doing assignment operation in if please correct

 if (value.type = typePlace && value.id == idPlace) 

to

if (value.type == typePlace && value.id == idPlace)

And please check the type of value it should not be a string.Before comparing you should check weather the type property is existing or not.

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

3 Comments

hello , in the html what I put is correct or not please
Hello neha , yes i tchecked the type . i want to know if what i put in html to disable image is correct or not :)?
Hello,Your function returns the actual value i.e the object it wont return true or false so i suggest please change the function in such a way that if your condition satisfies then return true else false ,so ng-if="false" will definitely disable your image.

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.