我正在使用express创建一个包含以下代码的小型网站:
<div class="container"> <h2>Active Users</h2> <hr> <table datatable [dtTrigger]="dtTrigger" class="table table-striped table-bordered hover">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody *ngIf="!showLoader">
<tr *ngFor="let user of users">
<td>{{user.local.username}}</td>
<td>{{user.local.email}}</td>
<td>
<div *ngIf="user.local.sub_end_dt && (user.local.sub_end_dt| amDifference : dateTo : 'days')>=0">
<span style="color: green;">{{(user.local.sub_end_dt| amDifference : dateTo : 'days')>=0?"Active":""}}</span>
<br>
<span>{{(user.local.sub_end_dt| amDifference : dateTo : 'days')}} Days Remaining</span>
</div>
<span style="color: red;">{{(user.local.sub_end_dt| amDifference : dateTo : 'days')<0||!user.local.sub_end_dt?"Expired":""}}</span>
</td>
<td>
<i class="fa fa-clipboard" aria-hidden="true" style="cursor: pointer;" (click)="copyPassword(user.local.password)" title="Copy Password"></i>
|<i class="fa fa-trash-o" aria-hidden="true" (click)="setAction('delete',user,'Do you wish to delete the user?')" data-toggle="modal" data-target="#confirmationModal" style="color: red; cursor: pointer;" title="Delete User"></i>
|<i class="fa fa-ban" *ngIf="user.local.sub_active" (click)="setAction('disable',user,'Do you wish to disable the user?')" data-toggle="modal" data-target="#confirmationModal" aria-hidden="true" style="color: orange;cursor: pointer;" title="Disable User" ></i>
<i class="fa fa-check" *ngIf="!user.local.sub_active" (click)="setAction('enable',user,'Do you wish to enable the user?')" data-toggle="modal" data-target="#confirmationModal" aria-hidden="true" style="color: green;cursor: pointer;" title="Enable User"></i>
|<i class="fa fa-user-secret" *ngIf="!user.admin" (click)="setAction('enableAdmin',user,'Do you wish to grant admin role to user?')" data-toggle="modal" data-target="#confirmationModal" aria-hidden="true" style="cursor: pointer;" title="Make User Admin"></i>
<i class="fa fa-user" style="color: grey;cursor: pointer;" *ngIf="user.admin" (click)="setAction('disableAdmin',user,'Do you wish to disable admin access for user?')" data-toggle="modal" data-target="#confirmationModal" title="Disable Admin User" aria-hidden="true"></i>
|<i class="fa fa-user-plus" aria-hidden="true" style="color: blue;cursor: pointer;" *ngIf="!user.support" (click)="setAction('enableSupport',user,'Do you wish to assign support to user?')" data-toggle="modal" data-target="#confirmationModal" title="Assign Support"></i>
<i class="fa fa-user-times" aria-hidden="true" data-toggle="modal" data-target="#confirmationModal" style="color: orange;cursor: pointer;" *ngIf="user.support" (click)="setAction('disableSupport',user,'Do you wish to disable support for user?')" title="Disable Support"></i>
</td>
</tr>
</tbody>
</table>
<div style="text-align: center;" *ngIf="showLoader">
<i class="fa fa-spinner fa-5x fa-spin" aria-hidden="true"></i>
</div> </div> <app-confirmation (action)="action($event)" [confirmationMessage]="message"></app-confirmation>
1)路由我的用户是否是最干净的方法? 2)使用这种方法,我怎么能有一个“header.html”文件,它将包括在我的所有页面之前?
答案 0 :(得分:1)
您可以在另一个文件中定义路由处理程序并将其导入
// my-route.js
var express = require('express');
var router = express.Router();
// About page route
router.get('/about', function (req, res) {
res.send('about page');
})
module.exports = router;
// index.js
var myRouteHandler = require('./my-route.js');
// ...
app.use('/prefix', myRouteHandler);