2

I hope not getting some minuses due to my question: I'm a newbie with angularjs and I want to use it to build a prototype of a real web application, it will be just for demo, the first page has a login page where it redirects to a welcome page with the username shown on top (Welcome John!) All the tutorials I found are based on a 1 page app, anyone can help me where can I find tutorial for this issue?

Thank you

4

2 回答 2

1

好吧,实际上大多数 Javascript MVC-s 的主要功能都属于单页应用程序,您应该多看看属于基于组件的解决方案的功能。

于 2013-06-13T12:26:45.580 回答
0

Jurka 对 MVC 功能和单页应用程序是正确的。要使用 Angularjs 完成身份验证,您必须首先了解基本概念。

我建议您首先阅读本教程:http ://docs.angularjs.org/tutorial以了解基本概念。

我已经购买了 O'Reilly 的 Angularjs 书,其中也涵盖了身份验证。这本书并不完美,但适合初学者理解一些见解。

基本上,您所要做的就是创建一个登录页面并将用户名/密码存储在一个 cookie 中,一旦提供以保持会话正常运行。如果您想针对服务器进行身份验证,如果您使用 angularjs-seed-project ( https://github.com/angular/angular-seed ),则可以在 app.js 中设置基本 HTTP 身份验证标头。这将确保每个请求都将标头解析到服务器。

'use strict';


// Declare app level module which depends on filters, and services
angular.module('cc', ['cc.filters', 'cc.services', 'userService', 'formFieldService', 'cc.directives'])
// Define routing
.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/user', {templateUrl: 'partials/user.html', controller: UserCtrl});
    $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: MyCtrl2});
    $routeProvider.otherwise({redirectTo: '/user'});
}])

// Set headers
.config(['$httpProvider', function ($httpProvider) {
    //delete $httpProvider.defaults.headers.common["X-Requested-With"]
    $httpProvider.defaults.headers.common['Authorization'] = 'Basic am9obkBqb2huLmNvbTpibGE=';
    $httpProvider.defaults.headers.common['Content-Type'] = 'application/json';
    $httpProvider.defaults.headers.common['Accept'] = 'application/json';
}]);

我希望这有帮助。

亲切的问候,克里斯

于 2013-06-13T13:06:10.750 回答