R3tep
R3tep

Reputation: 12864

Why my ng-show doesn't work?

I have the following code :

<div ng-init="showDetail = false">
    <table>
        <tbody>
            <tr ng-repeat="dataTable in arrayTableData">
                <td ng-repeat="data in dataTable.data" ng-click="showDetail = true;">{{data}}</td>
            </tr>
        </tbody>
    </table>
    <div ng-show="showDetail">
        <button ng-click="showDetail = false">Close</button>
    </div>
</div>

My variable showDetail changes value when you click on a data of the table, but my div showDetailCell not appear.

If I change the initialisation of showDetail with true the detail appear and disappear when you click on the button, but the click on the cell doesn't display showDetailCell.

Upvotes: 1

Views: 1707

Answers (1)

Fizer Khan
Fizer Khan

Reputation: 92745

ng-repeat will get its own scope. Due to Javascript inheritance, whenever variable from parent object is assigned in child scope will create new variable. It will no more reference to parent object variable. Better use . notation in the scope variable.

Instead of showDetail, use detail.toggle will solve the problem.

Upvotes: 1

Related Questions