Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. app.directive("dir", function($compile, $sce){
  2. return{
  3. restrict: "E",
  4. link: function(scope, element, attr){
  5. scope.$watch('content',function(){
  6. var html = $sce.trustAsHtml(attr.content);
  7. scope.alabala = $compile(html)(scope);
  8. },true);
  9. },
  10. template: "<div ng-bind-html='alabala'></div>",
  11. }
  12. });
  13.  
  14. function MainController($scope, $http, customService, $location, $sce, $compile){
  15. $scope.init = function(){
  16. customService.get().success(function(data) {
  17. var html = $sce.trustAsHtml(data);
  18. $("#dir").attr("content", data);
  19.  
  20. });
  21. };
  22. }
  23.  
  24. <div id="div" ng-controller="MainController" class="pull-right span3" ng-init="init()">
  25. <dir id="dir" ></dir>
  26. </div>
  27.  
  28. <button ng-click='click()'>Click me</button>
  29.  
  30. <dir id="dir" content="myVal"></dir>
  31.  
  32. $scope.myVal = '<button ng-click='buttonClick()'>I'm button</button>'; // HTML as string
  33.  
  34. myApp.directive('dir', function($compile, $parse) {
  35. return {
  36. restrict: 'E',
  37. link: function(scope, element, attr) {
  38. scope.$watch(attr.content, function() {
  39. element.html($parse(attr.content)(scope));
  40. $compile(element.contents())(scope);
  41. }, true);
  42. }
  43. }
  44. })
  45.  
  46. var App = angular.module('FormApp', [ 'ngRoute','ui.bootstrap', 'dialogs', 'oc.modal' ]);
  47.  
  48. App.config([ '$routeProvider', function($routeProvider) {
  49. $routeProvider.when('/addClient', {
  50. templateUrl : '../../resources/partialHtml/addClientLayout.html',
  51. controller : FormController
  52. }).when('/conflist/:commandName/:client/:env', {
  53. templateUrl : '../../resources/partialHtml/testPrase.html',
  54. controller : TestParseController
  55. }).when('/addNewCommand', {
  56. templateUrl : '../../resources/partialHtml/addNewCommand.html',
  57. controller : AddNewCommandController
  58. })
  59. } ]);
  60.  
  61. var TestParseController = function($scope, $window, $http, $routeParams, $sce,
  62. $compile) {
  63.  
  64. $scope.hide = function(obj) {
  65. alert($routeParams.commandName);
  66. };
  67.  
  68. $scope.to_trusted1 = function(html_code) {
  69. html_code = $sce.trustAsHtml(html_code);
  70. $scope.content = html_code;
  71. alert(html_code);
  72. $compile( document.getElementById('innerh'))($scope);
  73. };
  74.  
  75. $http.get('client/getConfList/' + $routeParams.commandName)
  76. .success(
  77. function(data) {
  78. $scope.html_content = "<button data-ng-click='hide($event)'>Click me!</button>";
  79. $scope.to_trusted1($scope.html_content);
  80. });
  81. }
  82.  
  83. <h3 data-ng-click="hide($event)" class="plus">Add</h3>
  84.  
  85. <div ng-bind-html="content" id="innerh"> </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement