javascript - Parse html with angular -


how parse html angularjs? have tried build filter this:

gameapp.filter('unsafe', function($sce) {     return function(val) {         return $sce.trustashtml(val);     }; }); 

i use in view:

<div ng-controller="gamectrl">     <table>         <p ng-bind-html="result | unsafe"></p>     </tr>     </table> </div> 

but don't work. result contains tr , td tags want fill table with.

here controller:

var gameapp = angular.module("gameapp", ['ngroute']);  gameapp.service('link', function() {     this.user = false; }); gameapp.filter('unsafe', function($sce) {     return function(val) {         return $sce.trustashtml(val);     }; });  function maketablefrom(str) {     var k = 1;     result = "";      for(var = 1; <= 8; i++) {         result += '<tr>';          for(var j = 1; j <= 20; j++) {             if(str[k] === '#') {                 result += '<td id=' + k + '">#</td>';             }             else if(str[k] === '&') {                 result += '<td class="click" val="water" id="' + k + '">&</td>';             }             else {                 result += '<td class="click" id="' + k + '"><a href="#"></a></td>';             }              k++;         }         result += '</tr>';     }     return result; }   gameapp.config(function($routeprovider) {     $routeprovider      .when('/', {             templateurl : 'partials/firstpage.html',             controller  : 'firstpagectrl'     })      .when('/game', {             templateurl : 'partials/game.html',             controller  : 'gamectrl'     });  });  gameapp.controller("firstpagectrl", function($scope,$http,link,$location) {     $scope.dologin = function() {         $http.post("lib/action.php", {username: $scope.username, password: $scope.password}).success(function(data) {             if(data) {                 link.user = data;                 console.log(link.user);                 $location.path("/game");             }         }).error(function(data) {             console.log(data);         });     }; });   gameapp.controller("gamectrl", function($scope,$http,link,$location) {     //$scope.trr = [1,2,3,4,5,6,7,8];     //$scope.tdd = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];     $scope.getmonsters = "1";     var map;      $http.post("lib/action.php", {monsters: $scope.getmonsters}).success(function(data) {         map = data;         console.log(map);         $scope.result = maketablefrom(data);         console.log($scope.result);     });      if(link.user) {         /*$scope.message = "fisk";         console.log(link.user);*/     } else {         /*$scope.message = "ledsen fisk";         console.log("Är inte satt");*/     } }); 

anyone can me?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -