Mawg
Mawg

Reputation: 40140

Angular-js ng-readonly when condition is false

I am trying to <inpute type="text" ng-readnly="!someVariable".

When I breakpoint, $scope.someVariable is true, but the input field is read-only.

Can I not use a ! ?

How can I code this?


[Update] If not,I imagine that I can ng-change the field and ignore the change if the condition is false.

Upvotes: 0

Views: 1653

Answers (2)

Yuva Raj
Yuva Raj

Reputation: 3881

The problem is not with your logic, it's with the code.

Look at your syntax :

<inpute type="text" ng-readnly="!someVariable"

Spelling issue inpute, ng-readnly and missing closing tag.

Change it to this,

<input type="text" ng-readonly="!someVariable">

WORKING DEMO

Upvotes: 1

Deadpool
Deadpool

Reputation: 8240

Pls see the following example:

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-readonly="play">
<button ng-click="toggle()">Toggle It</button>
<script>
//App declaration
var app = angular.module('myApp',[]);
//Controller Declaration
app.controller('myCtrl',function($scope){
    $scope.play = true;
    $scope.toggle = function(){
        $scope.play= !$scope.play;
    }
});

</script>
</body> 
</html> 

Hope, it helps!

As per your requirements, just change the required line to this:

<input type="text" ng-readonly="!play">

Upvotes: 0

Related Questions