2017-03-24 5 views
-1

こんにちは、テーブルにhtmlコードを挿入しようとしていますが、うまく機能していますが、いくつかの機能があります。 ?? HERESに機能:anglejsでhtmlコードを挿入するには

storyboard.getTmeLineTopDataKm= function (deviceId) { 

     var url = servername+'api/position/timeLineTopKm/'+deviceId; 

     console.log("Inside getMaxChaufeeurId " + url); 


     function onSuccess(response) { 
      console.log("+++++getMaxChaufeeurId SUCCESS++++++"); 

      if (response.data.success != false) { 
       //alert(JSON.stringify(response.data)); 
       $scope.km=response.data.km; 
       $scope.km2=response.data.km; 
       //alert(deviceId); 
          var elm=angular.element(document.querySelector('#ysf_'+deviceId)); 
          elm.append('<div style="margin-top:0px;margin-left:10px;"">'      
          +'<i ng-click="storyboard.getLastDayTimeLine()" style="cursor: pointer;padding-right:23px" class="fa fa-arrow-left " aria-hidden="true"></i>{{currentDatee}}' 
          +'<i style=" cursor: pointer;padding-left:23px" ng-click="storyboard.getForwardDayTimeLine()" class="fa fa-arrow-right " aria-hidden="true"></i> <br/> '      
          +'<i class="fa fa-road" aria-hidden="true" >'+ $scope.km2 +'Km'+'</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' 
          +'<i class="fa fa-tachometer" aria-hidden="true">' + $scope.speed2 +'km/h'+'</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' 
          +'<i class="fa fa-clock-o" style="color:green" aria-hidden="true"> 01:17</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' 
          +'<i class="fa fa-clock-o" style="color:red" style="padding:150px" aria-hidden="true"> 00:19</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' 
          +'<i class="fa fa-clock-o" style="color:orange" style="padding-right:160px" aria-hidden="true"> 02:51</i>' 

          +'</div>' 
          + '<div style="margin-top:7px;margin-left:10px;position:relative;" id="visualization2_'+deviceId+'"></div>' 
          ); 

      // alert($scope.km2); 






      //$scope.MyData=response.data; 
      } 
     }; 

     function onError(response) { 
      console.log("-------getMaxChaufeeurId FAILED-------"); 

      console.log(response.data); 
      console.log("Inside getMaxChaufeeurId error condition..."); 
     }; 

     //----MAKE AJAX REQUEST CALL to GET DATA---- 
     ajaxServicess.getData(url, 'GET', '').then(onSuccess, onError); 

    }; 

exempleの場合、この関数は= "storyboard.getLastDayTimeLineを()" NGクリック動作しません。

<table width="100%"> 
         <thead style="background-color: lightgray;"> 
         <tr> 
          <td style="width: 30px;"></td> 
          <td><p>Name</p></td> 
         <td><p>ID</p></td> 
         <td><p>GPS date</p></td> 
         <td><p>Adresse</p></td> 
         <td><p>Company</p></td> 
         </tr> 
         </thead> 
         <tbody> 
         <tr ng-repeat-start="device in MyDeviceObject"> 
          <td> 
          <button ng-if="device.expanded" ng-click="device.expanded = false">-</button> 
          <button ng-click="storyboard.getSelectedRow(device);device.expanded = true" ng-if="!device.expanded" >+</button> 
          </td> 
          <td><p>{{device.name}}</p></td> 
          <td><p>{{device.uniqueid}}</p></td> 
          <td><p>{{device.devicetime}}</p></td> 
          <td><p>{{device.adress}}</p></td> 
          <td><p>{{device.company}}</p></td> 
         </tr> 
         <tr ng-if="device.expanded" ng-repeat-end=""> 
          <td></td> 
          <td colspan="5" id="ysf_{{device.id}}" > 

          </div> 

          </td> 
         </tr> 
         </tbody> 
        </table> 
+0

なぜこのHTMLを.htmlファイルに追加しないのですか?必要に応じて 'ng-if'または' ng-show'を使用して非表示にしてください。 – Weedoze

+0

あなたは '$ comple'する必要があります –

+0

あなたのアイデアを説明できますか? –

答えて

0

あなたバインドHTML一度あなたが再完全にDOM

は属性としてごquerySelector要素にこのディレクティブを追加し、HTMLをレンダリングするために、それをコンパイルする必要がJSから。 DOMを再コンパイルします

.directive('bindHtmlCompile', ['$compile', function ($compile) { 
     return { 
      restrict: 'A', 
      link: function (scope, element, attrs) { 
       scope.$watch(function() { 
        return scope.$eval(attrs.bindHtmlCompile); 
       }, function (value) { 
        element.html(value); 
        $compile(element.contents())(scope); 
       }); 
      } 
     }; 
    }]); 
+0

querySelectorにbindHtmlCompileを追加する方法?? –

+0

いいえいいえこの属性をhtmlファイルの要素に割り当てます –

+0

バインドしている要素を表示 –

関連する問題