Angular 1.5组件方法templateUrl + function [英] Angular 1.5 component method templateUrl + function

查看:122
本文介绍了Angular 1.5组件方法templateUrl + function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用angular 1.5.0-beta.2的应用程序。

I'm trying to get an app working with angular 1.5.0-beta.2

要制作'指令',我有以下代码:

To make a 'directive' I have the following code:

myApp.component('gridshow', {
  bindings: {
    slides: '='
  },
  controller: function() {

  },
  controllerAs: 'grid',
  template: function ($element, $attrs) {
    // access to $element and $attrs
    return [
      '<div class="slidegrid">',
      '<div ng-repeat="slide in grid.slides">',
      '{{slide.image}}',
      '</div>',
      '</div>'
    ].join('')
  }
});

我喜欢模板的想法,该模板返回一个可以访问 $的函数元素 $ attrs 但是如何将它与templateUrl结合使用?

I like the idea of the template that returns a function with access to $element and $attrs but how do I combine this with a templateUrl?

推荐答案

在1.5.0-beta.2 templateUrl 可以是由注入器调用的函数。 $ element $ attrs 被注入 模板 templateUrl 组件中的函数,以及任何其他依赖项。

In 1.5.0-beta.2 templateUrl can be a function that is invoked by injector. $element and $attrs are injected into both template and templateUrl functions in component, as well as any other dependencies.

这意味着

  ...
  templateUrl: function ($element, $attrs) {
    // access to $element and $attrs
    ...
    return $attrs.uninterpolatedTemplateUrl;
  }

可以代替。

这篇关于Angular 1.5组件方法templateUrl + function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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