Search code examples
angularjsangularjs-scope

Set id using model in AngularJs


I am new to AngularJs and wanted to ask either it is possible in Angularjs to set id of an input field using model : $scope.modelName. In Jquery It can be done like:-

    $('.projShortName').attr('id', somevar);

Thank You


Solution

  • Yes you can provice id dynamically. In controller place following code:

    $scope.somevar = "ABC";
    

    And in Html place this:

    <input type="text" ng-model="abc" id="{{somevar}}"/>