0

I know that there are a lot of other similar questions but I didn't find the answer there.

<html ng-app="app" ng-controller="AppController">    
...
    <form class="navbar-form navbar-left" role="search" ng-submit="alert()">
         <div class="form-group">
             <input type="text" class="form-control search" ng-model="text" />
         </div>
         <button type="submit" class="btn btn-default icon-default icon-search">Submit                          </button>
    </form>
</html>
Taras Shchybovyk
  • 416
  • 4
  • 17

2 Answers2

3

You cant use alert (window.alert) function in angular as you normally do in plain javascript. This is example from angular $window service docs:

<script>
  function Ctrl($scope, $window) {
    $scope.greeting = 'Hello, World!';
    $scope.doGreeting = function(greeting) {
        $window.alert(greeting);
    };
  }
</script>
<div ng-controller="Ctrl">
  <input type="text" ng-model="greeting" />
  <button ng-click="doGreeting(greeting)">ALERT</button>
</div>

If you put doGreeting (name it as you want) function in your controller and inject $window, then your example should work:

...
<form class="navbar-form navbar-left" role="search" ng-submit="doGreeting()">
...
ndpu
  • 22,225
  • 6
  • 54
  • 69
2

Try to submit the form by adding ng-click in the button tag and call submit function by passing your form in the ng-click. The function is where you write your logic in the controller. submit

saipm
  • 89
  • 4