0

I'm trying to disable the div when a button is clicked using Angularjs. Onclick of a home button should disable one div of a same page by keeping the remaining div's active.

How can I achieve this?

My html code :

<button 
    style="margin-left: 22px; margin-top: 16px; background-color: #73AD21" 
    ng-click="getHome()">Home</button>

<div style="margin-top: 15px; display: inline-block" ng-repeat="imageSource in imageSources">
    <img width=40 height=50 style="margin-left: 12px;" ng-src="{{imageSource}}" /> <br> 
    <span style="margin-left: 12px;">{{getFilenameFromPath(imageSource)}}</span>
</div>

My js code:

$scope.imageSources = [];
$scope.imageSources.push('images/Open.png');
$scope.imageSources.push('images/New.jpg');
$scope.imageSources.push('images/Save.png');

$scope.getFilenameFromPath = function(filename) {
    return filename.split("/")[1].split(".")[0];
}
$scope.getHome = function() {
        
    window.location = "./Home.html";
}
9
  • can you provide the div you want to disable. Commented Jan 4, 2016 at 9:10
  • 1
    What do you mean by disable div ? Commented Jan 4, 2016 at 9:11
  • When I load the page,at the first I need to show the "MyDiv" div as active.when I click on the home button,I should disable the "MyDiv". Commented Jan 4, 2016 at 9:25
  • what is write on div ? is it form ? Commented Jan 4, 2016 at 9:27
  • My Div contains set of images which are horizontally aligned.So,I want to disable those images when I click on home button Commented Jan 4, 2016 at 9:30

2 Answers 2

0

According to your command, the code should be;

<button 
    style="margin-left: 22px; margin-top: 16px; background-color: #73AD21" 
    ng-click="getHome()">Home</button>

<div ng-if="showDiv" style="margin-top: 15px; display: inline-block" ng-repeat="imageSource in imageSources">
    <img width=40 height=50 style="margin-left: 12px;" ng-src="{{imageSource}}" /> <br> 
    <span style="margin-left: 12px;">{{getFilenameFromPath(imageSource)}}</span>
</div>

Your js code should be;

$scope.showDiv = true;
$scope.imageSources = [];
$scope.imageSources.push('images/Open.png');
$scope.imageSources.push('images/New.jpg');
$scope.imageSources.push('images/Save.png');

$scope.getFilenameFromPath = function(filename) {
return filename.split("/")[1].split(".")[0];
}
$scope.getHome = function() {
    $scope.showDiv = false;
    window.location = "./Home.html";
}
Sign up to request clarification or add additional context in comments.

4 Comments

I tried editing by the code you have suggested.But I'm unable to disable the div.
when you call getHome you want to hide your div. Did I understand correctly?
I have edited the answer please, try and let me know is there any problem.
can u please refer this url : stackoverflow.com/questions/34611021/…
0

Write ng-disabled in div tag and ng-click="noClickable()" with return false;

<div ng-disabled="disableDiv" ng-click = "noClickable()">....</div>

assign the $scope.disableDiv = true in in the function of controller controller

 $scope.noClickable = function(){
         $scope.disableDiv = true;
         return false; 
 }

  $scope.getHome = function() {
        $scope.disableDiv = true;
        window.location = "./Home.html";
    }

Please see this link Click
I hope this will work

Comments

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.