Salih KARAHAN
Salih KARAHAN

Reputation: 329

Why my angular code turns to comment?

I use angularjs. My html to be comment after render. Why? Before render code:

<select data-ng-model="selectedDate"> <option data-ng-repeat="date in OldRecords" value="{{}}">{{date}}</option> </select>

After render:

<section>

    <select data-ng-model="selectedDate" class="ng-pristine ng-valid">
        <!-- ngRepeat: date in OldRecords -->
    </select>

</section>

Upvotes: 2

Views: 558

Answers (4)

Arepalli Praveenkumar
Arepalli Praveenkumar

Reputation: 1306

<select data-ng-model="selectedDate">
   <option data-ng-repeat="date in OldRecords" value="{{}}">{{date}}</option>
</select>

Here OldRecords is an Empty Object.So that Angular make that to comment

Upvotes: 0

Lalit Sachdeva
Lalit Sachdeva

Reputation: 6619

I have tried the same code and its working fine for me. Here is the link for jsfiddle . Reason you are getting this comments is your list is not able to bind with the options. oldrecords is not able to bind with html. That's the only reason you are getting this comments.

app

angular.module('app', []).
controller('controller1', function($scope){
    $scope.OldRecords = ["banana", "apple", "peach"];
});

html:

<section ng-app="app" ng-controller="controller1">
    {{dummy}}
<select data-ng-model="selectedDate">
    <option data-ng-repeat="date in OldRecords" value="{{}}">{{date}}   </option>
</select>
</section>

Upvotes: 0

Sajad Karuthedath
Sajad Karuthedath

Reputation: 15767

It is a result of the element transclusion performed by ngRepeat.I think it doesn't affect any of your code or logic. These answers would also help and they also says the same thing

Remove helper HTML comments in Angular JS?

AngularJS leaves comments in HTML: is it possible to remove them?

Upvotes: 0

pratiklodha
pratiklodha

Reputation: 1125

Its better to use ng-options in this case ,

There is only a comment shown because $scope.OldRecords either doesn't exist or is empty.

Upvotes: 1

Related Questions