首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ui-sref不生成href

ui-sref不生成href
EN

Stack Overflow用户
提问于 2015-12-30 05:22:11
回答 2查看 1K关注 0票数 0

我不确定我在这里做的错误是什么,但是href没有生成。我已经按照ui-router示例进行了配置,但是当我将ui-sref放在ng-repeat中时,它不会生成URL,而且当我手动键入URL时,它也不起作用。

即使当我绑定到像data-ng-click="widget.open({widgetId: 1})这样的值设置时,也没有发生任何事情。

这是我的代码片段。

配置:

代码语言:javascript
复制
.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {

            $urlRouterProvider.otherwise('/');

            $locationProvider.html5Mode(true);

            $stateProvider
                .state('home', {
                    url: '/',
                    templateUrl: '/templates/home/home.html'
                })
                .state('widget', {
                    // With abstract set to true, that means this state can not be explicitly activated.
                    // It can only be implicitly activated by activating one of its children.
                    abstract: true,
                    // This abstract state will prepend '/widgets' onto the urls of all its children.
                    url: '/widget',
                    // Loading a template from a file. This is also a top level state,
                    // so this template file will be loaded and then inserted into the ui-view
                    // within index.html.
                    templateUrl: '/templates/widgets/index.html'
                })
                .state('widget.open', {
                    url: '/{widgetId:[\w+$]}', //matches  [a-zA-Z_0-9]
                    templateUrl: '/templates/widgets/index.html'
                })
                .state('widget.create', {
                    url: '/{type:[a-zA-Z]}', // We can test enum list also
                    templateUrl: '/templates/widgets/index.html'
                })
                .state('mashup', {
                    // With abstract set to true, that means this state can not be explicitly activated.
                    // It can only be implicitly activated by activating one of its children.
                    abstract: true,
                    // This abstract state will prepend '/mashups' onto the urls of all its children.
                    url: '/mashup',
                    // Loading a template from a file. This is also a top level state,
                    // so this template file will be loaded and then inserted into the ui-view
                    // within index.html.
                    templateUrl: '/templates/mashups/index.html'
                })
                .state('mashup.open', {
                    url: '/{mashupId:[\w+$]}', //matches  [a-zA-Z_0-9]
                    templateUrl: '/templates/mashups/index.html'
                })
                .state('mashup.create', {
                    url: '/{templateType:[a-zA-Z]}', // We can test enum list also
                    templateUrl: '/templates/mashups/index.html'
                });
        }])

模板:

代码语言:javascript
复制
    <div class="panel panel-default widget-list">
      <div class="panel-heading">
        <h3 class="panel-title">My Widgets ({{widgets.length}})</h3>
      </div>
      <div class="panel-body hp-content">
        <table class="table table-condensed table-bordered">
          <tbody>
          <tr data-ng-repeat="w in widgets">
            <td class="hp-type">Icon</td>
            <td>
              <div class="row">
                <div class="col-xs-12">
                  <a data-ui-sref="widget.open({widgetId: w.id })">{{::w.name}}</a>    
                </div>
              </div>
              <div class="row">
                <div class="col-xs-12 col-md-6">
                  {{::w.sourceId}}
                </div>
                <div class="col-xs-12 col-md-6">
                  {{::w.communityId}}
                </div>
              </div>
            </td>
            <td class="hp-actions">{{::w.access}}</td>
          </tr>
          </tbody>
        </table>
      </div>
      <div class="panel-footer">Panel footer</div>
    </div>

谁能指出我正在做的错误?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2015-12-30 05:31:59

不需要用大括号将widget.id括起来:

代码语言:javascript
复制
data-ui-sref="widget.open({widgetId: {{widget.id}} })

使用:

代码语言:javascript
复制
data-ui-sref="widget.open({widgetId: widget.id })">
票数 0
EN

Stack Overflow用户

发布于 2015-12-30 06:16:16

我认为你的问题是命名问题。你在一个widget in widgets的中继器中,所以当你做widget.open时,我认为它是在中继器的widget对象中寻找一个开放函数,而不是子路由'widget.open‘。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34519275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档