在 angularjs 中使用 $compile [英] Working with $compile in angularjs
本文介绍了在 angularjs 中使用 $compile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的对 angularjs 中的 $compile 感到困惑.任何人都可以帮助我,在 angularjs 中 $compile 有什么用处,例如其他然后在本文档中.https://docs.angularjs.org/api/ng/service/$compile一个>
解决方案
$compile 只是将文本编译为 html..
这是示例示例
angular.module("myModule", []).controller("myController", ['$scope', '$compile', function ($scope, $compile) {$scope.txt = "SampleTxt";$scope.submit = 函数 () {var html = $compile($scope.txt)($scope);angular.element(document.getElementById("display")).append(html);}}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><body ng-app="myModule" ><div ng-controller="myController"><textarea ng-model="txt" ></textarea><input type="button" value="submit" ng-click="submit()"/><div id="显示"></div>