Helo, I am working on an AngularJS app. I need help with routing. I am trying to navigate to index.html IF the login is successful (login.html). There are lots of examples about it but I could not get them to work with my application. Recently, I tried this , but still no luck.
I have 2 html pages; index.html and login.html. Also 2 seperate controller files for them; controller.js and logincontroller.js
Below my logincontroller.js
var myLogin = angular.module('myLogin', [])
myLogin.controller('MyLoginController', function($scope, $http)
{
$scope.Login = function(){
$http(
{...
})
.then(
function successCallback(response) {
$scope.loginresponse = response.data;
if($scope.loginresponse=="OK"){
// here go to index page
}
},
function errorCallback(response) {
alert("Failed to login!");
});
}
});
my controller.js(for index.html)
var myApp = angular.module('myApp',[ 'ui.bootstrap.datetimepicker', 'ngclipboard', 'hljs'])
myApp.controller("MyController", function TimeCtrl($scope, $timeout, $filter, $http, $window) {
});
in case needed part of: login.html
<!DOCTYPE html>
<html lang="en" data-ng-app="myLogin">
<meta charset="UTF-8">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="web-admin/libs/angular.js"></script>
<script src="web-admin/controllers/logincontroller.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
...
</head>
<body>
<div data-ng-controller="MyLoginController"> ...
index.html:
<!DOCTYPE html>
<html lang="en" data-ng-app="myApp">
<meta charset="UTF-8">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="web-admin/libs/angular.js"></script>
<script src="web-admin/controllers/controller.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
...
</head>
<body>
<div data-ng-controller="MyController">
I am confused about lots of things; one of them is that where should I put "config"? in controllerjs or logincontrollerjs or in a seperate file. If in seperate file, should I change data-ng-app in html files etc. Thanks in advance!