0

I have This Code

var VisualEditor = angular.module("VisualEditor", ["ngSanitize"]);
   VisualEditor.controller('VisualEditorController', function($scope, $sce) {
      $scope.Pages = [
       $sce.trustAsHtml('<div class="col-sm-12" style="height:3vh;background-color:#adb5b9;"><a class="DeletePage" ng-click="DeletePage($index)">x</a></div><div class="col-sm-12 Text"><p class="Paragraph" contenteditable="true">Write Your Text Here</p></div>'),
       $sce.trustAsHtml('<div class="col-sm-12" style="height:3vh;background-color:#adb5b9;"><a class="DeletePage" ng-click="DeletePage($index)">x</a></div><div class="col-sm-12 Text"><p class="Paragraph" contenteditable="true">Write Your Text Here</p></div>')
      ];
      $scope.DeletePage = function(index){
    $scope.Pages.splice(index, 1);
   };

Problem is

<a class="DeletePage" ng-click="DeletePage($index)">x</a>

which wont work. How can I delete element from $scope.Pages when user click on <a class="DeletePage" ng-click="DeletePage($index)">x</a>

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
EMM
  • 171
  • 2
  • 12
  • this has been asked and answered on this SO post here: [link](http://stackoverflow.com/questions/15453979/how-do-i-delete-an-item-or-object-from-an-array-using-ng-click) GL! – Shehryar Abbasi May 17 '15 at 19:22
  • @Shehryar I want to remove on ng-click in `x` But when I click on it, it don't remove the element. – EMM May 17 '15 at 19:35
  • EMM, look at this fiddle: https://jsfiddle.net/kksnhasn/ the splicing part works with JSON data..you may want to check the way you're using `$sce` (do you see any errors in the console?). Do you see the rendered snippets you have inside `$sce.trustAsHtml(//snippets)`? – Shehryar Abbasi May 17 '15 at 19:53
  • Additionally, take a look at this SO post [link](http://stackoverflow.com/questions/18340872/how-do-you-use-sce-trustashtmlstring-to-replicate-ng-bind-html-unsafe-in-angu) for `$sce.trustAsHtml` usage – Shehryar Abbasi May 17 '15 at 19:56
  • @Shehryar I don't want to display `HTML` tags using `{{person.name}}` except I want to save `EMM` in `$scope` and show it on page which can be done by saving `$sce.trustAsHtml('EMM')` in `$scope` – EMM May 17 '15 at 20:06
  • okay, take a look at this [link](http://stackoverflow.com/questions/21455814/accordion-with-ng-repeat-and-ng-bind-html-wont-work) , which also links to this plunker: [link](http://plnkr.co/edit/bbkNGJRiLeWwKBTKwPWv?p=info) and uses `ng-repeat` (for an array) with `$sce.trustAsHtml` and `ng-bind-html` --hope this helps, GL! – Shehryar Abbasi May 17 '15 at 20:28

0 Answers0