【问题标题】:angularjs how to set text inside element based on textbox inputangularjs如何根据文本框输入在元素内设置文本
【发布时间】:2015-07-01 23:55:43
【问题描述】:

我的代码是:

<div ng-controller="myCtrl">
    <div class="row">
        <div class="col-md-4 col-sm-3">
            <checked-input ng-scope="$eventID"></checked-input>
        </div>
        <div class="col-md-4 col-sm-3">
            <output ng-scope="$postbackOutput">***This is where I want the text typed in the textbox to go***</output>
        </div>
        <div class="col-md-3 col-sm-3">
            <a ng-click="generateURL($eventID)" class="btn-plus">
                <span class="glyphicon glyphicon-plus"></span>
            </a>
        </div>
     </div>
</div>

所以我要做的是获取位于第一列 div 内的 $eventID,然后在单击 &lt;a&gt; 标记中的链接时将其作为参数传递给函数调用 generateURL()第三列。在控制器内部我有:

app.controller('postbackCtrl', function($scope) {
    $scope.generateURL = function(eventID) {
        $scope.postbackOutput = eventID;
    } 
});

但它似乎没有正确设置&lt;output&gt; 中的文本。有人可以帮忙吗?我刚开始使用角度,所以有点混乱。

【问题讨论】:

    标签: javascript html angularjs angularjs-scope


    【解决方案1】:

    您可以使用车把括号将 var 绑定到视图:

    <output ng-scope="$postbackOutput">
        {{ postbackOutput }}
    </output>
    

    Here is a working plunkr

    【讨论】:

    • 感谢您的回复。试过了,它似乎也没有工作:(
    • 我添加了一个简单的 plunkr 来展示它的工作原理,我认为这是你想要完成的。另外,我只是查看了 ng-scope 指令,想知道这是否会造成混乱
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 2013-03-04
    • 2019-08-15
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多