我对角度全新,我有一个angularjs $ scope变量:
$scope.testme = "inputname",
我希望将此变量值分配给html元素的name属性。我想要
以下结果:
<input name="inputname" ...>
。但是如何从angularjs范围变量中获取它?
谢谢!
答案 0 :(得分:4)
请参阅更多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>