将参数传递给指令AngularJS

时间:2016-07-20 11:39:57

标签: html angularjs

所以我是AngularJS的新手所以不要判断所以我有两个按钮

 <button type="button" class ="btn btn-success"  data-toggle="modal" data-target="#myModal" >Add First List</button>
    <button type="button" class ="btn btn-success" data-toggle="modal" data-target="#myModal">Add Second List</button>

在指令中打开模态,我在指令上有两个实例..

<div my-div-table  type="modal" directivevarible="ctrl.FirstList" datasource="ctrl.tempList" ></div>
    <div my-div-table  type="modal" directivevarible="ctrl.SecondList" datasource="ctrl.tempList" ></div>

所以我想当我点击第一个按钮获取前2个变量时,我点击第二个按钮我想要获取第二个2变量..这是我的指令

app.directive('myDivTable',function () {
    
    var controller = ['$scope',function ($scope) {
            $scope.AddTempElem =function () {
                $scope.datasource.push({startDate: $scope.start, endDate: $scope.end, workInHours: $scope.hours});
            }
            $scope.Submit = function () {
                $scope.directivevarible = $scope.directivevarible.concat( $scope.datasource);
                $scope.datasource = [];
            }
            
        }],
        template=function (tElem,tAtrrs) {
            if(tAtrrs.type ==='table'){
                return 'template.html';
            }
            if(tAtrrs.type ==='modal'){
                return 'modal.html';
            }
            
        }
    return{
        scope:{
            datasource:'=',
            directivevarible:'='
        },
        controller:controller,
        templateUrl:template
    };
});

请帮帮忙?

0 个答案:

没有答案