I need assistance with implementing a feature in my HTML file. I have 2 buttons outside the form, and when either button is clicked, I want to show the form and set the value of the form element "role_id" to either 1 or 2 depending on which button was clicked. However, I am struggling to figure out how to write the code inside the controller to achieve this. Can anyone provide guidance? Index.html
<button class="btn btn-custom" ng-click="formToggle(1)" > Add Role 1</button>
<button class="btn btn-custom" ng-click="formToggle(2)"> Add Role 2</button>
<form class="form-horizontal" name="persForm" id="persForm" ng-submit="insertInfo(persInfo);" >
<input type="hidden" name="role_id" id="role_id" class="form-control" ng-model="persInfo.role_id" value="" />
</ form>
Controller.js
var crudApp = angular.module('crudApp',[]);
crudApp.controller("DbController",['$scope','$http', function($scope,$http){
$scope.formToggle = function(id){
$('#persForm').slideToggle();
//Code here to set form element ‘role_id’ to id
}
}]);
I've attempted using getElementById and other JavaScript DOM methods, but they don't seem to work within AngularJS.