Pass Textbox Data To A Javascript Array Using Angular -
what simplest way type in textbox, ng-click button , send text textbox array? i've put question marks show know code goes, i'm not sure what. here's code:
my html looks this:
<input class="textbox" style="width: 320px; color:black; margin-bottom:20px" type="text"/> <input class="button" style="width:100px" ng-click="addworkflow(?,?); toggleshow('addworkflow')" type="submit" value="add">
this js array want typed text go to, "name" , "description" objects.
$scope.addworkflow = function(?, ?) { var workflow = { id: 0, name: ?, description: ?, lens: "", focus: "", aperture: "" } $scope.workflows.push(workflow); };
well try this:
$scope.addworkflow = function(newworkflow) { var workflow = { id: 0, name:"this want text text box appear.", description: "", lens: "", focus: "", aperture: "" } var textbox=document.getelementsbyclassname("textbox")[0]; workflow.name=textbox.value; $scope.workflows.push(workflow); };
but if give input id="textbox"
better because class attribute given many elements , id specific 1 element:
<input class="textbox" id="textbox" style="width: 320px; color:black; margin-bottom:20px" type="text"/>
and use:
var textbox=document.getelementbyid("textbox"); workflow.name=textbox.value;
edit:
this how whould inputted values:
<input class="textbox" id="name" style="width: 320px; color:black; margin-bottom:20px" type="text"/> <input class="textbox" id="description" style="width: 320px; color:black; margin-bottom:20px" type="text"/> <input class="button" style="width:100px" ng-click="addworkflow(); toggleshow('addworkflow')" type="submit" value="add">
then function be:
$scope.addworkflow = function(newworkflow) { var workflow = { id: 0, name:"this want text text box appear.", description: "", lens: "", focus: "", aperture: "" } var nametext=document.getelementbyid("name"); workflow.name=nametext.value; var desctext=document.getelementbyid("description"); workflow.description=desctext.value; $scope.workflows.push(workflow); };
Comments
Post a Comment