0

In my view file I've one button. I want to append drop down on click of button. Here is my code:

Controller File

$scope.appendnewrow = function (result) {
  var tr = '<select><option ng-repeat="'+site in
  result+'">'+site.name+'</option></select>';
  var temp = $compile(tr)($scope);
  angular.element(document.getElementById('123')).append(temp);
}

View File

<a ng-click="appendnewrow(result)">Add domain</a>

When I ran this code options did not populate.

2
  • try encapsulating the function in $scope.$apply(function(){ }) Commented Apr 3, 2017 at 13:15
  • @bhanu.cs Can you explain more? Commented Apr 3, 2017 at 13:32

1 Answer 1

1

This is not the Angular way do to that.

Considering your data is in $scope.result, you can display the array using ng-options:

<a ng-click="addRow(row)">Add domain</a>
<select ng-options="site as site.name for site in result"></select>

Add this function in your controller:

$scope.addRow = function(newRow) {
    $scope.result.push(newRow);
}

Here is a JSFiddle demo of what it could looks like.

Sign up to request clarification or add additional context in comments.

1 Comment

No I don't want select tag in my view file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.