vendredi 24 juillet 2015

How can I do list of buttons using AngularJS?

I have some data which present similar search system (list of links on different source):

  1. First unit of data Show Detail

  2. Second unit of data Show Detail

  3. ...

Each unit of data has id (orderedNumber) and some information which must be hide by default. Each unit of data has button which shows this information. It's provide function ShowHide. I have problem because this function doesn't allow work with several buttons. Information about exactly unit of data must be shown when I click on the button (data is determined dinamically).

html:

    <div ng-repeat="x in results">
    {{ x.orderNumber + '. ' + x.namePackage + ' ' + x.size + ' Bytes '}} <a href={{x.link}}>Download</a> 
    <input type="button" value="Show detail" ng-click="ShowHide(x.orderNumber)" />
    <div ng-show = "IsVisible[orderedNumber]">response</div>
</div>

script.js:

    $scope.ShowHide = function (orderedNumber) {
    //This will hide the DIV by default.
    $scope.IsVisible[orderedNumber] = false;
    $scope.ShowHide = function (orderedNumber) {
        //If DIV is visible it will be hidden and vice versa.
        $scope.IsVisible[orderedNumber] = $scope.IsVisible[orderedNumber] ? false : true;
    }
};

How can I do list of buttons using AngularJS?




Aucun commentaire:

Enregistrer un commentaire