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!
The name attribute specifies a name for an HTML element. This name attribute can be used to reference the element in a JavaScript. For a <form> element, the name attribute is used as a reference when the data is submitted. For an <iframe> element, the name attribute can be used to target a form submission.
The ng-controller directive adds a controller to your application. In the controller you can write code, and make functions and variables, which will be parts of an object, available inside the current HTML element.
The HTML <input> name Attribute is used to specify a name for an <input> element. It is used to reference the form-data after submitting the form or to reference the element in a JavaScript. Syntax: <input name="name"> Attribute Values: It contains a single value name which describes the name of the <input> element.
The ng-bind-html directive is a secure way of binding content to an HTML element.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With