Richie
Richie

Reputation: 586

How can I concatenate two scope and assign new value

I am using AngularJS JavaScript trying to concatenate two variable in order to generate or use ng-bind-html as I need some dynamic value to be assigned once user clicks on a button. Here are my approach:

$scope.addRow = function(verifier){
    $scope.count = 1;
    console.log(verifier);

    if(!angular.isUndefined(verifier)) {
        $scope.row1= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row2= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row3= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row4= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row5= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row6= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
        $scope.row7= $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');
    }else{
        alert('You can not add new line to balance null object');
    }
}

Upvotes: 2

Views: 1205

Answers (1)

Shashank Agrawal
Shashank Agrawal

Reputation: 25797

It took me a while to understand your need. You need to write like this:

$scope.count = 1;

$scope["row" + $scope.count] = $sce.trustAsHtml('<input type="text"  class="form-control"   required="required">');

Upvotes: 1

Related Questions