I want to popup an alert message from an angularJS function, but it's not working.
Script
app.controller("APIController", function ($scope, $http) {
$scope.saveSubs = function () {
var sub = {
UserName: $scope.username,
Password: $scope.password
};
if ($scope.username === 'admin' && $scope.password === 'admin') {
window.location.href = '/Home/HotelSearchRedirect';
} else {
$window.alert("User name or password wrong. please enter correct username or password.");
}
};});
What is wrong with this code?
$window
needs to be injected.
app.controller("APIController", function ($scope, $http,$window) {
$scope.saveSubs = function () {
var sub = {
UserName: $scope.username,
Password: $scope.password
};
if ($scope.username === 'admin' && $scope.password === 'admin') {
window.location.href = '/Home/HotelSearchRedirect';
} else {
$window.alert("User name or password wrong. please enter correct username or password.");
}
};});
Just replace this code.
Only alert("User name or password wrong. please enter correct username or password.") will be suffice.
There is no need of window or $window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With