How to assign value of angularjs variable to html element attribute like elememnt input element name attribute

I'm completely new to angular, I have an angularjs $ scope variable:

$scope.testme = "inputname",

      

and I want to assign the name attribute of the html element to this variable value. I want to

the result below:

<input name="inputname" ...>

... But how to get it from angularjs scope variable?

Thank!

+3


source to share


1 answer


See https://docs.angularjs.org/guide/databinding for details

enter image description here



var app= angular.module("app",[]).controller('fCtrl', function($scope){

$scope.elementName = "testName";
$scope.myElement = {
  value:"some value",
  name:"myInput"
}
})
      

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="fCtrl">
  
  <input type="text" ng-model="myElement.value" name="{{myElement.name}}">
  <hr/>
  name only
  <br/>
  
  <input type="text" name="{{elementName}}">
  </div>
  
</div>
      

Run codeHide result


+3


source







All Articles