Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive("dir", function($compile, $sce){
- return{
- restrict: "E",
- link: function(scope, element, attr){
- scope.$watch('content',function(){
- var html = $sce.trustAsHtml(attr.content);
- scope.alabala = $compile(html)(scope);
- },true);
- },
- template: "<div ng-bind-html='alabala'></div>",
- }
- });
- function MainController($scope, $http, customService, $location, $sce, $compile){
- $scope.init = function(){
- customService.get().success(function(data) {
- var html = $sce.trustAsHtml(data);
- $("#dir").attr("content", data);
- });
- };
- }
- <div id="div" ng-controller="MainController" class="pull-right span3" ng-init="init()">
- <dir id="dir" ></dir>
- </div>
- <button ng-click='click()'>Click me</button>
- <dir id="dir" content="myVal"></dir>
- $scope.myVal = '<button ng-click='buttonClick()'>I'm button</button>'; // HTML as string
- myApp.directive('dir', function($compile, $parse) {
- return {
- restrict: 'E',
- link: function(scope, element, attr) {
- scope.$watch(attr.content, function() {
- element.html($parse(attr.content)(scope));
- $compile(element.contents())(scope);
- }, true);
- }
- }
- })
- var App = angular.module('FormApp', [ 'ngRoute','ui.bootstrap', 'dialogs', 'oc.modal' ]);
- App.config([ '$routeProvider', function($routeProvider) {
- $routeProvider.when('/addClient', {
- templateUrl : '../../resources/partialHtml/addClientLayout.html',
- controller : FormController
- }).when('/conflist/:commandName/:client/:env', {
- templateUrl : '../../resources/partialHtml/testPrase.html',
- controller : TestParseController
- }).when('/addNewCommand', {
- templateUrl : '../../resources/partialHtml/addNewCommand.html',
- controller : AddNewCommandController
- })
- } ]);
- var TestParseController = function($scope, $window, $http, $routeParams, $sce,
- $compile) {
- $scope.hide = function(obj) {
- alert($routeParams.commandName);
- };
- $scope.to_trusted1 = function(html_code) {
- html_code = $sce.trustAsHtml(html_code);
- $scope.content = html_code;
- alert(html_code);
- $compile( document.getElementById('innerh'))($scope);
- };
- $http.get('client/getConfList/' + $routeParams.commandName)
- .success(
- function(data) {
- $scope.html_content = "<button data-ng-click='hide($event)'>Click me!</button>";
- $scope.to_trusted1($scope.html_content);
- });
- }
- <h3 data-ng-click="hide($event)" class="plus">Add</h3>
- <div ng-bind-html="content" id="innerh"> </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement