简体   繁体   English

重定向到AngularJS中的另一个视图,以卸载当前页面中的所有视图

[英]Redirect to another view in AngularJS unloading all views in current page

I have following code in my index.html 我的index.html中有以下代码

 <div class="container"> <div class="row"> <!--display vendor details --> <div class="col-xs-6"> <ng-view></ng-view> </div> <!-- display chart --> <div class="col-xs-6"> <ng-include src="'partials/showchart.html'"></ng-include> </div> </div> </div> <!--display list of invoices --> <div class="container"> <ng-include src="'partials/invoicelist.html'"></ng-include> </div> 

I am displaying three views in the home page wherein the first row is divided in two columns displaying two views(Vendor details and a chart) and remaining page shows the third view(invoice list). 我在主页中显示三个视图,其中第一行分为两列,显示两个视图(供应商详细信息和图表),其余页面显示第三个视图(发票列表)。

Following is my code in InvoiceList table : 以下是我在InvoiceList表中的代码:

 <tbody> <tr ng-repeat="invoice in pendingInvoices"> <td> <a href="#/vendordetail/{{invoice.Invoice_Number}}"> {{invoice.Invoice_Number}} </a> </td> <td>{{invoice.Invoice_Date}}</td> <td>{{invoice.Invoice_Amount}}</td> </tr> </tbody> 

App.js App.js

 angular.module('Vendor', ['Vendor.Services', 'Vendor.Controllers', 'ngRoute', 'chartjs-directive']). config(['$routeProvider', function($routeProvider) { $routeProvider. when("/.vendordetail", { templateUrl: "partials/vendordetail.html", controller: "VendorController" }). when("/vendordetail/:id", { templateUrl: "partials/invoicedetail.html", controller: "InvoiceController" }). otherwise({ redirectTo: '/.vendordetail' }); } ]); 

Currently if the user clicks on the invoice number link the invoice details are loaded in the first column of the first row( replacing the Vendor Details, but other two views remain in the page ie chart and the invoice list). 当前,如果用户单击发票编号链接,则发票详细信息将加载到第一行的第一列中(替换供应商详细信息,但其他两个视图仍保留在页面中,即图表和发票列表)。 I want to display the invoice details in a new page(ie unload all the views). 我想在新页面中显示发票详细信息(即卸载所有视图)。 Is it possible? 可能吗?

Whenever you change views, only the template within <ng-view></ng-view> will change. 每当您更改视图时,只有<ng-view></ng-view>的模板会更改。 In order to accomplish this, you'll need to put the <ng-include> inside of your view. 为了做到这一点,您需要将<ng-include>放入视图中。

I went through the ui-router but it seems that it is still under active development. 我经历了ui-router,但它似乎仍在积极开发中。 So I ended up combining all the three views in one. 因此,我最终将所有三个视图合并为一个。 and it works fine now. 现在可以正常工作了。 So my new index.html is : 所以我的新index.html是:

 <div class="container"> <div ng-view> <ng-include src="'partials/vendordetail.html'"></ng-include> </div> </div> 

vendordetail.html contains the chart and invoice list views. vendordetail.html包含图表和发票列表视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM