Angular form Ubmit

Asked

Viewed 947 times

0

I am using the metronic with angular and I have the controller all right, however I tried to create a function that displays the user typed in a field in an Alert (in the future I will filter)...

html file :

angular.module('App').controller('UserProfileController', function($rootScope, $scope, $http, $timeout) {
    $scope.$on('$viewContentLoaded', function() {
        App.initAjax(); // initialize core components
        Layout.setSidebarMenuActiveLink('set', $('#sidebar_menu_link_profile')); // set profile link active in sidebar menu
        $scope.form.txt;
    });

    // set sidebar closed and body solid layout mode
    $rootScope.settings.layout.pageBodySolid = true;
    $rootScope.settings.layout.pageSidebarClosed = true;

    $scope.Submit = function() {
       alert($scope.form.txt);
     }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<form role="form" action="#" ng-submit="Submit()">
    <div class="form-group">
        <label class="control-label">First Name</label>
        <input type="text" ng-model="form.txt" placeholder="John" class="form-control" /> </div>
        <div class="margiv-top-10">
        <a input type="submit" id="submit"  ngClick="Submit()"  class="btn green-haze"> Save Changes </a>

    </div>
</form>

Does anyone know how to fix ? Obg

1 answer

1


You have 2 problems, and are in your html:

  1. ng-submit="Submit()" on the tag <form>, but your form does not have a button type="submit" (the attributes type and input do not exist in tags <a> )
  2. ngClick on your tag <a>, right is: ng-click

Below, the modified html code, I made other small fixes that improve the html functioning. See if it works now.

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<form role="form" action="" name="form_user_info">
    <div class="form-group">
        <label for="first_name" class="control-label">First Name</label>
        <input id="first_name" type="text" ng-model="form.txt" placeholder="John" class="form-control" /> </div>
        <div class="margiv-top-10">
          <a href="javascript:void(0)" id="submit" ng-click="Submit()" class="btn green-haze"> Save Changes </a>
        </div>
    </div>
</form>

  • It worked... thank you very much ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.