角度渲染模板没有绑定

时间:2016-09-26 18:46:17

标签: angularjs

我一直不知道如何在没有绑定的情况下将角度模板完全渲染为HTML。

示例:

scope.value1 = 99;
scope.value2 = "cat";
scope.div_class = "red-cell";

var template = '<div class="{{ div_class }}">{{ value1 }}, {{ value2 }}</div>';
var linkFn = $compile(template);
var content = linkFn(scope);

console.log(content);

输出是具有角度绑定的DOM元素:

<div class="{{ div_class }} ng-binding ng-scope">{{ value1 }}, {{ value2 }}</div>

我想要的是一个没有绑定的渲染元素

<div class="red-cell">99, cat</div>

我知道一次性绑定。但是,由于我已经处理了很多渲染,我认为这比我模板中的一堆1TB更清晰。

这是否可以角度?

澄清:我想将模板渲染为静态HTML。将有许多变量,因此需要使用范围/上下文进行渲染。

3 个答案:

答案 0 :(得分:0)

而不是<div>{{ value }}</div>,您可以尝试<div ng-bind-html="value"></div>并查看它是否有效吗?

答案 1 :(得分:0)

如果您不希望将已生成的类添加到呈现的html中,则需要:
 1.模板中没有可绑定的内容。
 2.或者您需要将debuginfoenabled设为false:

myInsert :: Ord a => a -> [a] -> [a]
myInsert x [] = [x]
myInsert x (y:ys) = if x < y then x:y:ys else y:myInsert x ys

insertionSort :: Ord a => [a] -> [a]
insertionSort [] = []
insertionSort [x] = [x]
insertionSort (x:xs) = myInsert x (insertionSort xs)

答案 2 :(得分:0)

如果你想要静态html,那么只需确保你有一个静态模板:

main.bundle.js:44225 EXCEPTION: Cannot read property 'profileService' of undefinedErrorHandler.handleError @ main.bundle.js:44225next @ main.bundle.js:29109schedulerFn @ main.bundle.js:30625SafeSubscriber.__tryOrUnsub @ main.bundle.js:574SafeSubscriber.next @ main.bundle.js:523Subscriber._next @ main.bundle.js:476Subscriber.next @ main.bundle.js:440Subject.next @ main.bundle.js:2027EventEmitter.emit @ main.bundle.js:30617onError @ main.bundle.js:31257onHandleError @ main.bundle.js:64707ZoneDelegate.handleError @ main.bundle.js:89163Zone.runTask @ main.bundle.js:89095ZoneTask.invoke @ main.bundle.js:89260
main.bundle.js:44230 ORIGINAL STACKTRACE:ErrorHandler.handleError @ main.bundle.js:44230next @ main.bundle.js:29109schedulerFn @ main.bundle.js:30625SafeSubscriber.__tryOrUnsub @ main.bundle.js:574SafeSubscriber.next @ main.bundle.js:523Subscriber._next @ main.bundle.js:476Subscriber.next @ main.bundle.js:440Subject.next @ main.bundle.js:2027EventEmitter.emit @ main.bundle.js:30617onError @ main.bundle.js:31257onHandleError @ main.bundle.js:64707ZoneDelegate.handleError @ main.bundle.js:89163Zone.runTask @ main.bundle.js:89095ZoneTask.invoke @ main.bundle.js:89260
main.bundle.js:44231 TypeError: Cannot read property 'profileService' of undefined
    at http://localhost:4200/main.bundle.js:50624:18
    at new ZoneAwarePromise (http://localhost:4200/main.bundle.js:89434:29)
    at RegisterComponent.validateUsername (http://localhost:4200/main.bundle.js:50623:16)
    at http://localhost:4200/main.bundle.js:7776:49
    at Array.map (native)
    at _executeAsyncValidators (http://localhost:4200/main.bundle.js:7776:23)
    at FormControl.asyncValidator (http://localhost:4200/main.bundle.js:7763:28)
    at FormControl.AbstractControl._runAsyncValidator (http://localhost:4200/main.bundle.js:21641:41)
    at FormControl.AbstractControl.updateValueAndValidity (http://localhost:4200/main.bundle.js:21615:22)
    at FormControl.setValue (http://localhost:4200/main.bundle.js:21878:14)ErrorHandler.handleError @ main.bundle.js:44231next @ main.bundle.js:29109schedulerFn @ main.bundle.js:30625SafeSubscriber.__tryOrUnsub @ main.bundle.js:574SafeSubscriber.next @ main.bundle.js:523Subscriber._next @ main.bundle.js:476Subscriber.next @ main.bundle.js:440Subject.next @ main.bundle.js:2027EventEmitter.emit @ main.bundle.js:30617onError @ main.bundle.js:31257onHandleError @ main.bundle.js:64707ZoneDelegate.handleError @ main.bundle.js:89163Zone.runTask @ main.bundle.js:89095ZoneTask.invoke @ main.bundle.js:89260
main.bundle.js:50624 Uncaught TypeError: Cannot read property 'profileService' of undefined