简体   繁体   English

模板中的角度ng-href

[英]Angular ng-href in template

I have this in a template that is in a route in Angular: 我在Angular中的路由模板中拥有此功能:

<a class="btn btn-default" ng-href="/create>Create</a>

I have this route defined: 我定义了以下路线:

.when("/create", {
        templateUrl: page_root + 'html/createhtml'
    })

The link links to http://mysite/create instead of http://mysite/somepath#!/create 该链接链接到http://mysite/create而不是http://mysite/somepath#!/create

Why is this? 为什么是这样? On the main page (not in a <ng-view> section of the page I have: 在主页上(不在页面的<ng-view>部分中):

<a class="navbar-brand" ng-href="/">Home</a>

This creates the proper link http://mysite/somepath 这将创建正确的链接http://mysite/somepath

Why does the template not know where the root of the site is? 为什么模板不知道站点的根目录在哪里?

You should quote the href as '#create' instead of '/create'. 您应将href引用为“ #create”而不是“ / create”。 You may also verify if the href property is appropriately generated by inspecting the anchor element. 您还可以通过检查锚元素来验证href属性是否正确生成。

<a class="btn btn-default" ng-href="#create">Create</a>

Also I don't see any advantage of using ng-href for static Urls. 我也看不到将ng-href用于静态Urls的任何优势。 You should simply use href . 您应该只使用href

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

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