Инструменты пользователя

Инструменты сайта


angular:angularjs:servisy:compile

$compile

беглый обзор

Компилирует HTML-строку или DOM в шаблон и создает шаблонную функцию, которую затем можно использовать для связи области и шаблона.
$compile просто скомпилировать текст в html ..

Простой пример:

         angular
                .module("myModule", [])
                .controller("myController", ['$scope', '$compile', function ($scope, $compile) {
                    $scope.txt = "<b>SampleTxt</b>";
                    $scope.submit = function () {
                        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="display"></div>
    </div>
</body>
angular/angularjs/servisy/compile.txt · Последние изменения: 2023/01/12 12:18 (внешнее изменение)