I'm new to AngularJS, and may be doing something completely wrong, therefore, don't judge too strictly please.
I have a form:
<form method="post" action="/secured/login_check" id="login-form" submit="loginCheck()" name="loginForm">
<input type="text" name="_username" ng-model="data.username"/>
<input type="password" name="_password" ng-model="data.password"/>
<button class="btn btn-primary" type="submit">Sign in</button>
</form>
And I have an application:
var smsApp = angular.module('smsApp', []);
smsApp.controller('LoginCtrl', function($scope) {
$scope.loginCheck = function() {
$.ajax({
url: '/secured/login_check', // here I want to use form action attr value
data: {
_username: $scope.data.username,
_password: $scope.data.password
},
success: function(){
console.log('logged in');
},
error: function(){
console.log('login failed');
}
});
};
});
smsApp.directive('submit', function() {
return function (scope, element, attrs) {
element.bind('submit', function() {
scope.$apply(attrs.submit);
return false;
});
}
});
My main question is: how can I pass attrs and/or element to $apply call? Or how else can I get this information inside $scope.loginCheck? This is to set the ajax's url parameter dynamically.
I, of course, can use $('#login-form').attr('action') inside the loginCheck procedure, but I believe there can be a better way ("more angular way") of doing that.
The reason why I want to take this attribute, is that it's generated from a PHP application and it's different for dev and prod environments. Moreover, I want to have it configurable in one place rather then in multiple ones.
p.s. If you can provide a completely different solution, but keeping the original idea, I'd be also interested in it.