Reputation: 977
I am totally new to angular, I have an angularjs $scope variable:
$scope.testme = "inputname",
and I want to assign this variable value to a name attribute of html element. I want
the below result:
<input name="inputname" ...>
. But how to get it from angularjs scope variable?
Thank you!
Upvotes: 8
Views: 50875
Reputation: 16498
Please see more https://docs.angularjs.org/guide/databinding
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>
Upvotes: 5