在ng-repeat中使用href

时间:2016-04-10 03:25:24

标签: angularjs twitter-bootstrap angularjs-scope angular-ui-router angularjs-ng-repeat

我使用AngularFire和Firebase来存储包含titleurl的对象。我称之为对象list。我想:

  1. ng-repeat通过我的对象数组。
  2. 使用list.url下载网址内容。所有网址都是指向.js.css文件的链接。
  3. 将下载链接/功能应用于嵌套在button(Bootstrap 3.3.6)中的input-group
  4. 所有这些都是在路由视图(ui-router
  5. 内完成的

    What the buttons look like within the input-group

    这是我的div。它嵌套在路由视图中。我正在处理input-group-btn中的第一个按钮。

    <div class="list-group">
    <a class="list-group-item" ng-repeat="(id, link) in links | filter: search | orderBy: '-downloadCount' | limitTo: 5">
        <h4 class="align-left list-group-item-heading">{{ link.name }}</h4>
        <h4 class="align-right list-group-item-heading">{{ link.downloadCount }}</h4>
        <br>
        <br>
        <div class="list-group-item-text">
            <div class="input-group">
                <input type="text" class="form-control" readonly value="{{ link.url }}" />
                <div class="input-group-btn">
                    // *** IT'S THIS FIRST LINK THAT ISN'T WORKING ***
                    <button class="btn btn-default" ng-href="{{link.url}}"><i class="glyphicon glyphicon-download"></i></button>
                    <button class="btn btn-primary" ng-click="copyToClipboard(link)" tooltip-placement="bottom" uib-tooltip="Copy"><i class="glyphicon glyphicon-copy"></i></button>
                </div>
            </div>
    
        </div>
    </a>
    </div>
    

    当我使用锚标签而不是按钮标签时,ng-repeat变得疯狂,链接变得混乱,格式变得混乱,并且最终只有一个按钮的副本没有&#39甚至工作。

    我不确定我是否应该插入ng-href所指的链接,但是我已经尝试过和不使用,我仍然没有什么都有。

    这是我的JS回答评论。

    var ref = new Firebase('https://myApp.firebaseio.com/links');
    
    $scope.links = $firebaseArray(ref);
    
    $scope.addLink = function () {
        $scope.links.$add({
            name: $scope.newLinkName,
            url: $scope.newLinkUrl,
            downloadCount: 1
        });
        $log.info($scope.newLinkName + ' added to database');
        $scope.newLinkName = '';
        $scope.newLinkUrl = '';
    };
    
    $scope.incrementDownloadCount = function (link) {
        link.downloadCount += 1;
        var tempCount = link.downloadCount;
        var currentRef = new Firebase('http://myApp.firebaseio.com/links/' + link.$id);
        // update the downloadCount
        currentRef.update({ downloadCount: tempCount });
        // update priority for sorting
        currentRef.setPriority(tempCount);
        $log.info(link.name + ' downloadCount changed to ' + link.downloadCount);
    };
    
    // Possibly relevant includes
    ui.router
    ui.bootstrap
    firebase
    

0 个答案:

没有答案