首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角指令鼠标/滑鼠工作,但不设置为初始状态后鼠标

角指令鼠标/滑鼠工作,但不设置为初始状态后鼠标
EN

Stack Overflow用户
提问于 2015-09-23 22:51:57
回答 1查看 283关注 0票数 6

我有一个指令,它在模板和鼠标中心上显示学生信息列表,然后显示其他学生信息。我想回到最初的状态。

尝试了所有的资源,但运气不佳。

html --这就是我要注入指令的地方

代码语言:javascript
复制
<div ng-repeat="student in studentPortfolio">
<portfolio-view student="student"></portfolio-view>
</div>

html指令模板

代码语言:javascript
复制
<div class="outer-box">
  <img src="{{student.picture}}" alt="{{student.name.first}} {{student.name.last}}" style="width: 200px; height: 200px">
  Name: {{student.name.first}} {{student.name.last}}
  <br>Bio: {{student.Bio}}
  <br>
  Skills:
<div ng-repeat="skill in student.skills">
{{skill.title}}
  </div>

  <br>
</div>

指令

代码语言:javascript
复制
app.directive('portfolioView', function() {
  return {
    restrict: 'E',
    scope: {
      student: "="
    },
    templateUrl: '/html-templates/hoverPortfolio.html',
    link: function(scope, elem, attrs) {
      //gets the first project and shows it
      var project = scope.student.projects;
      var firstProject = project[0];
      var fp_name = firstProject.name;
      var fp_type = firstProject.projectType;
      var fp_description = firstProject.description;
      //gets the second project and shows it
      var secondProject = project[1];
      var sp_name = secondProject.name;
      var sp_type = secondProject.projectType;
      var sp_description = secondProject.description;
      //the template that shows the second project
      var newHtml =
        '<div class="projects outer-box"><div class="firstproject"> Project Name: ' +
        fp_name + '<br>Type: ' + fp_type + '<br>Description: ' +
        fp_description +
        '</div><br><div class="secondproject"> Project Name: ' +
        sp_name + '<br>Type: ' + sp_type + '<br>Description: ' +
        sp_description +
        '</div> </div>';

      elem.on('mouseenter', function() {
        elem.html(
          newHtml
        )
      });

      elem.on('mouseleave', function() {
      //return to intial state
      });
    }
  }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-24 00:38:26

我没有您的数据,但是ng-show可以工作,就像在这个小提琴中一样。

这里有一个简单的变体。如果模板包含您希望显示或隐藏的部分,并在其中包含一个ng-show变量,则您的指令可能相当简单:

代码语言:javascript
复制
return {
    restrict: 'EAC',
    replace: true,
    template: '<div><div ng-show="show">show</div><div ng-show="!show">hide</div></div>',
    link: function (scope, element, attrs, controller) {
        scope.show = true;
        element.on('mouseenter', function () {
            scope.$apply(function () {
                scope.show = false;
            });
        });
        element.on('mouseleave', function () {
            scope.$apply(function () {
                scope.show = true;
            });
        });
    }
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32750751

复制
相关文章

相似问题

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