123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <html>
- <head>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/angular2-polyfills.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/Rx.umd.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.14/angular2-all.umd.min.js"></script>
- <script src="../lib/php_crud_api_transform.js"></script>
- <script>
- AppComponent =
- ng.core.Component({
- selector: 'my-app',
- providers: [ng.http.HTTP_PROVIDERS],
- template: '<ul><li *ngFor="#x of posts">{{ x.id + ", " + x.content }}</li></ul>'
- })
- .Class({
- constructor: [
- ng.http.Http, function(http) {
- // add withCredentials
- let _build = http._backend._browserXHR.build;
- http._backend._browserXHR.build = () => {
- let _xhr = _build();
- _xhr.withCredentials = true;
- return _xhr;
- };
- var url = "../api.php";
- http.post(url,JSON.stringify({username:"admin",password:"admin"})).subscribe(res => {
- url += "/posts?csrf="+JSON.parse(res._body);
- http.post(url,JSON.stringify({user_id:1,category_id:1,content:"from angular2"})).subscribe();
- http.get(url).map(res => php_crud_api_transform(res.json())).subscribe(res => this.posts = res.posts);
- });
- }
- ]
- });
- document.addEventListener("DOMContentLoaded", function(event) {
- ng.core.enableProdMode();
- ng.platform.browser.bootstrap(AppComponent);
- });
- </script>
- </head>
- <body>
- <my-app>Loading...</my-app>
- </body>
- </html>
|