Angular form submit

0

I am using metronic with angular and I have the controller all right, however I tried to create a function that displays what 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><formrole="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 it? Obg

    
asked by anonymous 08.03.2017 / 17:37

1 answer

1

You have 2 problems, and they are in your html:

  • ng-submit="Submit()" in the <form> tag, but its form does not have a button type="submit" (the type and input attributes do not exist in tags <a> )
  • ngClick in its <a> tag, the right one is: ng-click
  • Below the modified html code, I've made other small corrections that improve the working of html. See if it works now.

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script><formrole="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>
        
    10.03.2017 / 20:58