获取angularjs

时间:2015-05-24 16:58:56

标签: javascript angularjs model-view-controller

我大约2天前开始使用角度。我仍然围绕如何做很多事情。现在,我正在尝试显示一个工具提示,其中包含有关所点击的&#34;标记&#34;的信息。我定义了一个&#34;标签&#34;作为具有<span>的{​​{1}}元素,如此:

ng-toolkit

我的控制器是这样的:

<div id="list-of-words" ng-controller="inlineEditorController" ng-click="hideTooltip()">
    <!-- This is the tooltip. It is shown only when the showtooltip variable is truthful -->
    <div id="tooltip" class="tooltip" ng-click="$event.stopPropagation()" ng-show="showtooltip">
        <input type="text" ng-model="value" />
    </div>
    <div ng-repeat="w in words">
      <span class="tag" ng-click="toggleTooltip($event)">{{w.content}}</span>
    </div>
  </div>
我试图做的就是改变“编辑我”。&#39;显示来自var app = angular.module('myApp', []); app.controller('inlineEditorController', ['$scope', function($scope){ $scope.inlineEditor = function(){ $scope.showtooltip = false; $scope.value = 'Edit me.'; $scope.hideTooltip = function(){ $scope.showtooltip = false; } $scope.toggleTooltip = function(e){ e.stopPropagation(); $scope.showtooltip = !$scope.showtooltip; } }; })]); 的内容,但我不知道如何做到这一点。到目前为止,我所尝试的一切都失败了。

2 个答案:

答案 0 :(得分:0)

要获取可以使用的项目内容:

      <span class="tag" ng-click="toggleTooltip($event,w.content)">{{w.content}}</span>

所以,控制器应该是:

 $scope.toggleTooltip = function(e,content){
            e.stopPropagation();
            $scope.showtooltip = !$scope.showtooltip;
            $scope.value = content;
    }

答案 1 :(得分:0)

您可以使用$event.currentTarget来获取元素。即你控制器中的e.currentTarget