AngularJS格式化templateURL中范围值的文本

时间:2014-06-16 06:02:34

标签: angularjs angularjs-directive angularjs-scope

我有一个指令<some-directive ver="val"></some-directive>,它根据ver值返回带有动态句子的templateUrl。我一直在尝试添加换行值,以便在嵌入到模板中时文本显示为两行,但\r\n仅添加空格但不添加新行。

directive('someDirective', function(){
    return {
        restrict: 'E',
        scope: true,
        link: function (scope, element, attrs) {
            //based on scope or attrs customize the first reply
            var type=attrs.ver;
            switch(type) {
            case 'val1':
                scope.lm = { 
                    eng: 'This is my sentence that needs a break in the middle.',
                    cha: 'This is another sentence that needs a break in the middle.'
                };
              break;
            case 'val2':
                scope.lm = { 
                    eng: 'This is my sentence that needs a break in the middle.',
                    cha: 'This is another sentence that needs a break in the middle.'
                };
              break;
            default:
                scope.lm = { 
                    eng: 'This is my sentence that needs a break in the middle.',
                    cha: 'This is another sentence that needs a break in the middle.'
                };
            }
        },
        templateUrl : 'content/excerpts/some-template.html'

    }
});

感谢任何帮助。

谢谢 AJG

0 个答案:

没有答案