0

first i want apologie for my English but i will try be specific as i can.

Secondly probably solution for this is simple but im stuck and my brain dont want cooporate, beer dosen't help too.. at least this time

So i writing app in angular where i display a table of some data with ng repeat and in each row i need to have buttons like edit, delete etc, for each button i have diffrent partials of modals defining in directives.

And there is a problem because when i load the view, ng-repeat add for each row that directive with template but i want to call directive when i click on specific button in row not for all rows when view is loaded

    <h4 class="modal-title">Name for: {{name}}</h4>

<add-button></add-button>

<table class="table table-hover">
    <thead>
    <tr>
        <input type="search" placeholder="search" ng-model="findThisData">
        <td>Id</td>
        <td>Name</td>
    </tr>
    </thead>
    <tr ng-repeat="data in DataOne | filter:findDataOne | orderBy: 'id'">

        <td>{{data.id}}</td>

        <td ng-model="data.name">{{data.name}}</td>

        <td>
       **strong text**

            <edit-input></edit-input>
            <delete-button></delete-button>
        </td>
    </tr>
</table>

EditButton partial:

    <button class="btn btn-success" type="button" data-toggle="modal" data-target=".bs"
        ng-click="modalContent(data.id, $index)" >Edytuj{{data.name}}
</button>
<div  class="modal fade bs" role="dialog" id="yolo">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title">Edycja{{data.version}}</h4>
            </div>
            <div class="modal-body">
                <input type="text" ng-model="input.name"/>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" ng-click="save(input.name)" data-dismiss="modal">Zapisz</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">Zamknij</button>
            </div>
        </div>
    </div>
</div>

Directives:

    define(['angular'], function () {
    'use strict';
    var dataDirectives = angular.module('dataModule.dataDirectives', []);

    dataDirectives.directive('dataName', function(){
        return{
            restrict: 'AE',
            templateUrl: '/front/app/views/users/dataName.html'
        }
    });


    dataDirectives.directive('editInput', function (){
        return{
            restrict: 'AE',
            templateUrl: '/front/app/views/partials/editInput.html'

        }
    });

    dataDirectives.directive('modalName', function () {
        return{
            restrict: 'AE',
            templateUrl: '/front/app/views/partials/modalname.html'
        }
    });
    dataDirectives.directive('deleteButton', function () {
        return{
            restrict: 'AE',
            templateUrl: '/front/app/views/partials/deleteButton.html'
        }
    });
   dataDirectives.directive('addButton', function (){
        return {
            restrict: 'AE',
            templateUrl: '/front/app/views/partials/addButton.html'
        }
    });
});

So my goal is to have a edit and delete button in each row in table and when i click on this button i want to call action with modal template but only for this specific data in row

Vakrol
  • 1

1 Answers1

0

You could add an input variable for your directives and use them like:

<edit-input rowId="data.id"></edit-input>
<delete-button rowId="data.id"></delete-button>

You can achieve that by using an isolate scope in your directive. Here are some useful links that explain how to do that:

Community
  • 1
  • 1
Stefan Ch
  • 329
  • 2
  • 7