- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 ngroute 模块在同一页面中使用不同主题路由我的应用程序,使用此示例:
<html>
<head>
<title>Angular JS Views</title>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-route.min.js"></script>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app = "mainApp">
<p><a href = "#addStudent">Add Student</a></p>
<p><a href = "#viewStudents">View Students</a></p>
<div ng-view></div>
<script type = "text/ng-template" id = "addStudent.htm">
<h2> Add Student </h2>
{{message}}
</script>
<script type = "text/ng-template" id = "viewStudents.htm">
<h2> View Students </h2>
{{message}}
</script>
</div>
<script>
var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/addStudent', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).
otherwise({
redirectTo: '/addStudent'
});
}]);
mainApp.controller('AddStudentController', function($scope) {
console.log("adssadsd");
$scope.message = "This page will be used to display add student form";
});
mainApp.controller('ViewStudentsController', function($scope) {
$scope.message = "This page will be used to display all the students";
});
</script>
</body>
</html>
这样。在我的应用程序中尝试:html文件:
<!DOCTYPE html>
<!-- saved from url=(0066)https://hackerstribe.com/guide/IT-bootstrap-3.1.1/examples/signin/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-route.min.js"></script>
<script type="application/javascript"></script>
<script src="scripts/login-controller.js"></script>
<script src="scripts/rest-services.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="images/puzzle.png" />
<title>Login</title>
<!-- Bootstrap core CSS -->
<link href="./styles/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./styles/signin.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="StaffManagement" ng-controller="LoginController" ng-fa>
<div class="container">
<script type = "text/ng-template" id = "addStudent.htm">
<h2> Add Student </h2>
{{message}}
</script>
<script type = "text/ng-template" id = "viewStudents.htm">
<h2> View Students </h2>
{{message}}
</script>
<form class="form-signin" role="form" ng-controller="LoginController" ng-submit="submitCredentials()" novalidate>
<h2 class="form-signin-heading">Hai bisogno di autenticarti</h2>
<input type="email" class="form-control" placeholder="Email address" required="" autofocus="" id="email" ng-model="staffLoginForm.email">
<input type="password" class="form-control" placeholder="Password" required="" id="password" ng-model="staffLoginForm.pass">
<label class="checkbox">
<input type="checkbox" value="remember-me"> Ricordami
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body></html>
js关联文件:
//'use strict'; //questo mi da informazione sull'errore
var app = angular.module("StaffManagement", ['ngRoute']);
app.controller("LoginController", function($scope, $http, restService) {
$scope.stafflogins = [];
$scope.staffLoginForm = {
email: "",
pass: ""
};
$scope.tokenStaffForm = {
idtokenstaff: -1,
tokenstaff: ""
};
$scope.staffForm = {
idstaff : -1,
staffType: {
idstaffType: -1,
type: ""
},
name: "",
surname: "",
birthDate: "",
phone: "",
gender: true,
working: true,
staffLogin: {
idstaffLogin: -1,
email: "",
pass: ""
}
};
//8njae3j4b54fpoapftc8aofbfs
//admin: l5qsngh3v9a5f2v9p55ar4h083
$scope.submitCredentials= function() {
restService.login($scope.staffLoginForm, _logsuccess, _logerror);
//$location.url('edit_employee.html');
// console.log($scope.staffLoginForm);
/* $http({
method : 'POST',
url : 'http://localhost:8080/FoodDrinkDispener/rest/tokenstaff',
data : angular.toJson($scope.staffLoginForm),
}).then(function successCallback(response) {
if (typeof response.data === 'object'){
_logsuccess(response)
return response.status;
}
else
_logerror(response);
},function (response) {
console.log($scope.tokenStaffForm);
_logerror(response);
}
);*/
}
/*
function _SetToken(CurrentToken) {
sessionStorage.setItem("token", (CurrentToken === null) ? null : JSON.stringify(CurrentToken));
//console.log(CurrentToken);
}
*/
function _logsuccess(response) {
console.log("Loggato correttamente");
console.log(response.status);
var CurrentToken = response.data;
// _SetToken(CurrentToken);
}
function _logerror(response) {
console.log("Login fallito");
console.log(response.status);
// _SetToken(null);
}
/* $http({
method : 'GET',
url : 'http://localhost:8080/FoodDrinkDispener/rest/stafflogin/byemail/'+$scope.staffLoginForm.email
}).then(function successCallback(response) {
$scope.stafflogins = response.data;
}, function errorCallback(response) {
console.log(response.statusText);
});
if(MD5($scope.stafflogins.pass)==$scope.staffLoginForm.pass)*/
// console.log(sessionStorage.getItem.toString);
});
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/sessionexpired', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).
otherwise({
redirectTo: '/addStudent'
});
}]);
app.controller('AddStudentController', function($scope) {
console.log("ciao");
$scope.message = "This page will be used to display add student form";
});
app.controller('ViewStudentsController', function($scope) {
console.log("ciao");
$scope.message = "This page will be used to display all the students";
});
在 js 文件中,我放置了我的 Controller 和我的配置:
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/sessionexpired', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).
otherwise({
redirectTo: '/addStudent'
});
}]);
app.controller('AddStudentController', function($scope) {
console.log("ciao");
$scope.message = "This page will be used to display add student form";
});
app.controller('ViewStudentsController', function($scope) {
console.log("ciao");
$scope.message = "This page will be used to display all the students";
});
我也尝试过 console.log("ciao");
,但是当我尝试这个 url 时:file:///C:/Users/Giacomo%20B/Desktop/progetto%20mainetti/prove%20angular/fddWebapp/login.html#/viewStudents 什么也没有出现,console.log 也没有:
问题在哪里?为什么我的 Controller 不起作用?
最佳答案
我看到几个问题:
<div ng-view></div>
在您的 html 页面中标记'/addStudent'
,但您没有配置此路由(我想 '/sessionexpired'
应该重命名为它)ng-controller="LoginController"
两次,我想最后一次就够了。关于javascript - Angular ngroute : controllers doesnt's work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41193836/
当我们写 angular.module('app',['ngRoute']); 这里的依赖到底是什么意思? 最佳答案 准确地说,ngRoute 只不过是一个简单的 Angular 模块,如 angul
我有一个非常奇怪的错误,我已经设置了路线和 Controller 。现在我只有一个没有错误的空白页面? index.html; Rekentalent.nl: Ben j
如果我尝试使用 ngRoute 方法更改主页面 View ,我有一个网络应用程序似乎根本无法工作。路由配置如下所示: var app; app = angular.module('genehaxx',
我想让这个简单的路由工作,但无法弄清楚问题出在哪里。 这是 HTML: . . .
我尝试通过导航栏使用 ngRoute 导航到其他 HTML 页面,但是当我单击导航栏上的不同按钮时,页面上没有显示任何内容。 Index.html 文件: table, th , td {
我正在创建一个 Angular 应用程序。文件结构如下: index.html login.html js/index.js index.html内容为
为什么我有这个错误?这是我的错误: “无法实例化模块 ngRoute” 详细信息: “ Uncaught Error :[$injector:modulerr] http://errors.angul
我的自定义指令中的隔离范围有问题。 我已经构建了一个自定义指令。当我没有使用父作用域在指令中设置作用域属性时,它起作用了。 它做了什么?它呈现了一个原生的 JavaScript 控件。每次加载站点时,
我在函数中传递 /?preview=true 并在 app.js $route.current.params.preview 中捕获。但是当我在控制台日志中输出 $route.current.para
我的代码遇到问题。 刷新 localhost:portnumber/home 或/todos 或/contacts 上的页面时崩溃 -> 使用重播无法获取/home 或/todos 或/contact
我的应用程序在几个小时前运行良好。现在,当我进入一个页面、触发一个事件时,应用程序会返回到主菜单。 我是这样使用 ngRoute 的: app.js angular.module('starter',
我是 Angular 新手,很难让 ngRoute 获取我的模板文件。 这是我的index.html:
我创建了一个网络应用程序,运行完美。现在我需要使用稍微不同的 Controller 创建几乎完全相同的 html 页面。我正在尝试使用 ngRoute 但它不起作用,我也不是 100% 相信我的路线会
我的 ng-route 与我在网页上实现的动画滚动冲突: 这是我的滚动元素: Next 其中“#one”是部分ID,其中滚动到goto-next是图像类,scrolly用于平滑滚动动画。 这是我的 n
我正在开发一个新的 Angularjs 网络应用程序,我必须在其中使用 ngRoute。首先我有点困惑,因为在我的情况下路由根本不起作用 - 我总是在 index 结束。和 MainCtrl。 在 i
我有四个文件: angularjs.js scripts.js ngroute.js index.html 现在,我配置了以下路由: var myApp = angular.module("myApp
我的应用程序可以与 ngRoute 配合使用,但是当我尝试直接访问我的部分(从地址栏)时,它仅返回该部分(没有主页)。如何隐藏这些部分以防止直接访问? 说明:我有一个有 2 个街区的站点。第一个是菜单
我有一个索引页面(登录),其中存在注册链接,因此在重定向时我尝试加载 Controller ,但它没有加载,控制台中也没有错误。 我的主页正在加载 URL:http://localhost:8081/
好吧,我是 Angular 的新手,为了测试我在 Codecademy 上获得的技能,我正在做一个音乐艺术家的测试网站。第一页是艺术家列表。当您单击其中一位艺术家的 block 时,它会在同一页面上加
是否可以向 AngularJS 应用程序中的所有路由添加基本 URL?本质上是改变它在服务器上的位置(有点,如果这有意义的话......所以它不会通过 / 而是通过 /something/ 访问)。
我是一名优秀的程序员,十分优秀!