Skip to content

Commit 4579f20

Browse files
committed
Added angular2 auth example
1 parent 277cb2b commit 4579f20

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/client_angular2_auth.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<html>
2+
<head>
3+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/angular2-polyfills.min.js"></script>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/Rx.umd.min.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/angular2-all.umd.min.js"></script>
6+
<script src="../lib/php_crud_api_transform.js"></script>
7+
<script>
8+
AppComponent =
9+
ng.core.Component({
10+
selector: 'my-app',
11+
providers: [ng.http.HTTP_PROVIDERS],
12+
template: '<ul><li *ngFor="#x of posts">{{ x.id + ", " + x.content }}</li></ul>'
13+
})
14+
.Class({
15+
constructor: [
16+
ng.http.Http, function(http) {
17+
// add withCredentials
18+
let _build = http._backend._browserXHR.build;
19+
http._backend._browserXHR.build = () => {
20+
let _xhr = _build();
21+
_xhr.withCredentials = true;
22+
return _xhr;
23+
};
24+
var url = "../api.php";
25+
http.post(url,JSON.stringify({username:"admin",password:"admin"})).subscribe(res => {
26+
url += "/posts?csrf="+res._body;
27+
http.post(url,JSON.stringify({user_id:1,category_id:1,content:"from angular2"})).subscribe();
28+
http.get(url).map(res => php_crud_api_transform(res.json())).subscribe(res => this.posts = res.posts);
29+
});
30+
}
31+
]
32+
});
33+
document.addEventListener("DOMContentLoaded", function(event) {
34+
ng.core.enableProdMode();
35+
ng.platform.browser.bootstrap(AppComponent);
36+
});
37+
</script>
38+
</head>
39+
<body>
40+
<my-app>Loading...</my-app>
41+
</body>
42+
</html>

0 commit comments

Comments
 (0)