ctrl.js
In controller the value is true if user is landing on edit page
var self = this;
self.edit = "true"
html
On add page it should be
<md-input-container flex="25">
<label>GameId</label>
<input name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" custome-directive-to-check-unique-value >
</md-input-container>
On edit page it should be
<md-input-container flex="25">
<label>GameId</label>
<input name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" disabled>
</md-input-container>
For disable I can use ng-disabled=ctrl.edit
to make input field disabled how, to do for directive custome-directive-to-check-unique-value
ctrl.js
In controller the value is true if user is landing on edit page
var self = this;
self.edit = "true"
html
On add page it should be
<md-input-container flex="25">
<label>GameId</label>
<input name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" custome-directive-to-check-unique-value >
</md-input-container>
On edit page it should be
<md-input-container flex="25">
<label>GameId</label>
<input name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" disabled>
</md-input-container>
For disable I can use ng-disabled=ctrl.edit
to make input field disabled how, to do for directive custome-directive-to-check-unique-value
- self.edit = "true" ? as string , or boolean – Shushanth Pallegar Commented Nov 26, 2015 at 11:19
- It is a boolean field and its working fine just need how to remove custom directive .. able to do the field disabled perfectly – Mr X Commented Nov 26, 2015 at 11:22
3 Answers
Reset to default 2You can simply use the attribute ng-show
or ng-hide
based on the value.
<div ng-hide="edit">Edit is False</div>
<div ng-show="edit">Edit is True</div>
If edit is true then the ng-show would be true showing the message Edit is True
You can use two input fields and use ng-if
to show one of the fields based on a bool value which specify whether it is add view or edit view.
<input ng-if="!ctrl.edit" name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" custome-directive-to-check-unique-value >
<input ng-if="ctrl.edit" name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" disabled>
you can use
ng-disabled
directive to disable or enable your input text, but as i see you have done this already.- As for the directive disable, why dont you use an if statement inside your directive body and check what you need to do according to your
ctrl.edit
value.
- As for the directive disable, why dont you use an if statement inside your directive body and check what you need to do according to your
to do this just pass the ctrl.edit
from your input text to your directive like this:
html
<input name="games" ng-model="ctrl.game" ng-required="true" ng-maxlength="50" custome-directive-to-check-unique-value myFlag = "ctrl.edit">
directive
.directive('customeDirectiveToCheckUniqueValue', function () {
return {
restrict: 'AE',
scope:{
myFlag :'='
},
link: function (scope, element, attrs) {
//here make your condition and add your code accordingly
if(myFlag){
//if true your code
}else{
//if false your code
}
}
};
})
hope helps,good luck.