文字
分享

AngularJS: API: ng/provider/$interpolateProvider

$interpolateProvider

  1. - $interpolate
  2. - provider in module ng

用于配置插值标记。默认为{{}}

用法

$interpolateProvider();

方法

  • startSymbol([value]);

    表示字符串中的插值表达式开始的符号。默认为{{

    参数

    参数 类型 详述
    value
    (可选)
    string

    用于设置开始符号的新值。

    返回值

    stringself

    getter访问时返回当前符号,setter时返回自身。

  • endSymbol([value]);

    表示字符串中的插值表达式结束的符号。默认为}}

    参数

    参数 类型 详述
    value
    (可选)
    string

    用于设置结束符号的新值。

    返回值

    stringself

    getter访问时返回当前符号,setter时返回自身。

示例

index.html

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &apos;Courier New&apos;, monospace;font-size:inherit;padding:0px;color:inherit;background-color:transparent;white-space:pre-wrap;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;"><span style="box-sizing:border-box;color:navy;"><script></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

var</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> customInterpolationApp </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">=</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> angular</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">module</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'customInterpolationApp'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">,</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">[]);</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 

customInterpolationApp</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">config</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">Function</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">$interpolateProvider</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">)</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">{</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

  $interpolateProvider</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">startSymbol</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'//'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">);</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

  $interpolateProvider</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">endSymbol</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'//'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">);</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">});</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

 

 

customInterpolationApp</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">controller</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">(</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">'DemoController'</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">,</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">Function</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">()</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">{</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

    </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">this</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">.</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">label </span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">=</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">"This binding is brought you by // interpolation symbols."</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">;</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">});</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"></span><span style="box-sizing:border-box;color:navy;">

</script></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"></span><span style="box-sizing:border-box;color:navy;">

<div</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:teal;">ng-app</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">=</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">"App"</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);"> </span><span style="box-sizing:border-box;color:teal;">ng-controller</span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">=</span><span style="box-sizing:border-box;color:rgb(221, 17, 68);">"DemoController as demo"</span><span style="box-sizing:border-box;color:navy;">></span><span style="box-sizing:border-box;color:rgb(51, 51, 51);">

  //demo.label//

</span><span style="box-sizing:border-box;color:navy;"></div></span></code>

protractor.js

1

2

<code style="box-sizing: border-box; font-size: inherit; padding: 0px; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px;"><span style="box-sizing: border-box;">it</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box; color: rgb(221, 17, 68);">'should interpolate binding with custom symbols'</span><span style="box-sizing: border-box;">,</span><span style="box-sizing: border-box;"> </span><span style="box-sizing: border-box;">Function</span><span style="box-sizing: border-box;">()</span><span style="box-sizing: border-box;"> </span><span style="box-sizing: border-box;">{</span><span style="box-sizing: border-box;">

expect</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box;">element</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box;">by</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">binding</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box; color: rgb(221, 17, 68);">'demo.label'</span><span style="box-sizing: border-box;">)).</span><span style="box-sizing: border-box;">getText</span><span style="box-sizing: border-box;">()).</span><span style="box-sizing: border-box;">toBe</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box; color: rgb(221, 17, 68);">'This binding is brought you by // interpolation symbols.'</span><span style="box-sizing: border-box;">);</span><span style="box-sizing: border-box;">});</span></code>