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>
1
  • 4
    That's nice - what's the actual issue, an error? What is alert() Commented Jun 17, 2014 at 17:35

2 Answers 2

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()">
...
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.