Angular 1.5组件... ng-link问题

时间:2016-08-22 06:58:03

标签: javascript angularjs angularjs-service angularjs-1.5 angular-component-router

我有导航栏 Home Accounts Services Orders Tickets 点击帐户,其中包含新客户搜索客户字段的下拉列表点击新客户,它应该导航到主页组件。

根组件的视图:

<div class="dropdown">
    <a class="dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        <span class="tab_ico fa fa-user"></span>
        <span class="tab_name">ACCOUNTS</span>
        <span class="caret_holder"><span class="caret"></span></span>
    </a>
    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
        <li><a href="#"><span class="tab_ico fa fa-search"></span> Search customer</a></li>
        <li><a ng-link="['Home']"><span class="tab_ico fa fa-user"></span> New customer</a></li>
    </ul>
</div>

正如您所见,ng-link =“['Home']”

routeConfig:

$routeConfig: [  
    { path: "/dashboard", component: "dashboard",name:"Dashboard",useAsDefault: true },  
    { path: "/home", component: "home", name:"Home" },  
    { path: "/account", component: "account", name:"Account" },  
    { path: "/**", redirectTo: ["Home"] }  
],  

主页组件

angular.module('app.home').component("home", {
    templateUrl: "app/components/home/homeview.html",

    controllerAs: "model",
    controller: function($scope, dataservice) {
        var vm = this;
        console.log("entered into home component");

    }
})

主页组件视图

<div>
    <ul>
        <li><span class="tab_ico fa fa-search"></span> SEARCH CUSTOMER <span class="closetab">x</span></li>
        <li class="k-state-active"><span class="tab_ico fa fa-user"></span> Identification <span class="closetab">x</span></span></li>
    </ul>
</div>

点击新客户后,它应显示主页组件视图,但它不显示主页组件视图?,也没有错误。!!

1 个答案:

答案 0 :(得分:0)

您可以<a>使用href元素而不<a href="#" ng-link="['Home']"><span class="tab_ico fa fa-user"></span> New customer</a>

而不是

<a ng-link="['Home']"><span class="tab_ico fa fa-user"></span> New customer</a>

使用此

href

我认为Trim可能是问题所在。

来源Angular Router docs