0

I have html template:

<div ng-controller="MyController">
  <form novalidate>
    Name: <input type="text" ng-model="user.name" />
    <button ng-click="greet(user)">GREET</button>
  </form>
</div>

And I add it like this:

"<div ng-include src=\"'/views/template.html'\"></div>"

This is function in MyController:

$scope.user = {}
    $scope.greet = function (user) {
        alert('hello ' + user.name)
    }

But when I click on button it makes submit it doesn't call greet function.
I also tried to add type="button" to it but it is the same.
Here is the working solution so I don't know what I am missing.

1110
  • 7,829
  • 55
  • 176
  • 334
  • I tried the code you provided, and no submit of form on my side. Probably in the application you have another handler which forces the form submission. – Dmitri Pavlutin Dec 27 '15 at 17:19

1 Answers1

1

use type="submit" with the submit button, and input instead of button.

MYK
  • 825
  • 12
  • 25
  • I tried that it also maked postback. In the example that I added it's the same code I added. – 1110 Dec 27 '15 at 16:56
  • I've recreated this scenario in plunker, seems to be working fine: http://plnkr.co/edit/PEElwQLyTZRLK536pwFv?p=preview – MYK Dec 27 '15 at 17:04
  • You are right it works. This is probably some issue with template and popup in this directive. When I try same code without template it works but in template it doesn't. – 1110 Dec 27 '15 at 17:33