P
P
podvox232017-10-19 15:51:00
JavaScript
podvox23, 2017-10-19 15:51:00

How to pass string to form from JS to Angular?

You need to enter a string into the element from the browser and submit the form.

<form class="form-horizontal form-horizontal_search ng-valid ng-valid-required ng-dirty" role="form" name="efBpForm" ng-submit="action.search()" novalidate="">
<input ng-model="searchParameters.agreementNumber" placeholder="" class="form-control form-base__form-control ng-pristine ng-valid clearable" clearable="" name="">

I do it like this in the chrome devtools console:
let elementInput = angular.element('input[ng-model="searchParameters.agreementNumber"]');
elementInput.val('101');
elementInput.scope().$apply();
angular.element('form[ng-submit="action.search()"]').submit();

Visually, the input is filled, the form is submitted, but returns the result as if it were empty. As I understand it, Angular simply does not see the string that I enter. How to make him see her?
PS I don't know Angular at all. HTML is not mine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Petrov, 2017-10-19
@podvox23

You have you don't have to do

let elementInput = angular.element('input[ng-model="searchParameters.agreementNumber"]');
elementInput.val('101');
elementInput.scope().$apply();

but enough: since angular has a two-way binding

N
Negwereth, 2017-10-19
@Negwereth

https://docs.angularjs.org/guide/databinding#!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question