值未以角度传递给控制器

时间:2014-05-05 05:50:02

标签: javascript angularjs angularjs-scope

<div ng-repeat="tack in feed">
    <div class="pin" ng-if="selected == tack.boards">
        <a href="{{ tack.link }}"><h3>{{ tack.title }}</h3></a>
        <img src="{{ tack.imageURL || 'http://www.designofsignage.com/application/symbol/building/image/600x600/no-photo.jpg' }}" />
        <p>
             {{ tack.desc }}
        </p>
        <br>
        <p>
             <button ng-click="deleteTack(tack.link)" class="btn btn-danger">Delete</button>
        </p>
    </div>
</div>

我试图在我的控制器中写入的函数中传递一个值。但是值没有传递给控制器​​。

tack.link或从ng-repeat标签获取的任何其他值外,其他参数的字符串将被传递。

1 个答案:

答案 0 :(得分:1)

工作正常!!!

看看这个

<强> Working Demo

<强> HTML

   <div ng-app='myApp' ng-controller="Controller">
    <div ng-repeat="tack in feed">
        <div class="pin" ng-if="selected == tack.boards"> <a href="{{ tack.link }}"><h3>{{ tack.title }}</h3></a>

            <img src="{{ tack.imageURL || 'http://www.designofsignage.com/application/symbol/building/image/600x600/no-photo.jpg' }}" style="width:100px;height:100px;" />
            <p>{{ tack.desc }}</p>
            <br>
            <p>
                <button ng-click="deleteTack(tack.link)" class="btn btn-danger">Delete</button>
            </p>
        </div>
    </div>
</div>

<强>脚本

var app = angular.module('myApp', []);
app.controller('Controller', function ($scope) {

    $scope.feed = [{
        boards: 'selected',
        link: 'link_1',
        title: 'title_1',
        desc:'desc_1'
    }, {
        boards: 'selected',
        link: 'link_2',
        title: 'title_2',
        desc:'desc_2'  
    }, {
        boards: 'selected',
        link: 'link_3',
        title: 'title_3' ,
        desc:'desc_3' 
    }, {
        boards: 'selected',
        link: 'link_6',
        title: 'title_6',
        desc:'desc_6' 
    }, {
        boards: 'selected',
        link: 'link_4',
        title: 'title_4',
        desc:'desc_4'
    }, {
        boards: 'selected',
        link: 'link_5',
        title: 'title_5',
        desc:'desc_5'
    }];

    $scope.deleteTack = function(link)
    {
        alert(link);
    }
});