如何将此代码从angular1转换为angular2? [英] How to convert this code from angular1 to angular2?

查看:69
本文介绍了如何将此代码从angular1转换为angular2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有, 我想在角度2中使用 ng-class ="{active:isOpen()}" 但是我不知道如何将这段代码从angular1转换为angular2, 有人帮我吗? 非常感谢你. 我的代码从这里开始: http://www.theme-guys.com/唯物主义/角度/#/apps/todo

there, i want use ng-class="{active: isOpen()}" in angular 2, but i don't know ,how to convert this code from angular1 to angular2, any one help me? thank you very much. my code from there:http://www.theme-guys.com/materialism/angular/#/apps/todo

app.directive('menuToggle', ['$location', function($location) {
  return {
    restrict: 'A',
    transclude: true,
    replace: true,
    scope: {
      name: '@',
      icon: '@'
    },
    templateUrl: 'assets/tpl/directives/menu-toggle.html',
    link: function(scope, element, attrs) {
      icon = attrs.icon;
      if ( icon ) {
        element.children().first().prepend('<i class="' + icon + '"></i>&nbsp;');
      }

      element.children().first().on('click', function(e) {
        e.preventDefault();
        link = angular.element(e.currentTarget);

        if( link.hasClass('active') ) {
          link.removeClass('active');
        } else {
          link.addClass('active');
        }
      });

      element.find('a').ripples();

      scope.isOpen = function() {
        folder = '/' + $location.path().split('/')[1];
        return folder == attrs.path;
      };
    }
  };
}]);

 
<li menu-link="" href="#/" class="ng-isolate-scope">
          <a ng-transclude="" ng-class="{active: isOpen()}" href="#/ui-elements/cards" class=""><span class="ng-scope">Cards</span><div class="ripple-wrapper"></div></a>
        </li>

推荐答案

如何将此代码从angular1转换为angular2?"

"How to convert this code from angular1 to angular2?"

3个简单步骤:

1-您进入此页面:

https://angular.io/docs/ts/latest/guide/upgrade.html

2-您尝试自己做.

3-如果您有任何特定的问题(问题,而不是免费工作要求),请访问 http://stackoverflow.com 并提问在那里.

3- If you have any specific questions (questions, not free work requests) you go to http://stackoverflow.com and ask them there.

我希望这会有所帮助.

这篇关于如何将此代码从angular1转换为angular2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆