javascript - AngularJS: why can't I inject html in my view? -


i'm very new angularjs , saw solutions on so, but, due inexperience, can't figure out how achieve task solutions, i'm asking help, please bear me. basically, question says, need inject , render html in view. here code:

html

<tabset panel-tabs="true" panel-class="panel-grape" ng-controller="maincontroller" data-heading="other news">    <div ng-repeat="tab in basestring" ng-bind-html-unsafe="tab">      </div>  </tabset> 

and part of controller:

function createbase() {     (var = 0; < $scope.news.news[0].posizioni.length; i++) {         // $scope.tabsname[i] = $scope.news.news[0].posizioni[i][i];     $scope.basestring[i] =["<tab heading='" + $scope.news.news[0].posizioni[i][i] + "' ng-controller='maincontroller'><div class='col-xs-12 col-sm-6 col-md-6' id='colonadx"+ $scope.news.news[0].posizioni[i][i] +"'></div><div class='col-xs-12 col-sm-6 col-md-6' id='colonasx"+ $scope.news.news[0].posizioni[i][i] +"'></div><div id='paginaz"+ $scope.news.news[0].posizioni[i][i] +"'></div></tab>"];     } } 

i need tabsname remain array.

over last few hours, have tried several solutions, far i'm not able obtain results...please can me out? lot in advance.

edit better understanding number of tab header depends on results json:

portion of json:

    {    "news":[       {          "posizioni":[             {                "0":"allnews"             },             {                "1":"secondtab"             }          ]        } ] } 

in angular, html in controller red flag; it's wrong place.

instead, use ng-repeat, close tried, build html, here's quick example.

in controller, keep data:

$scope.data = {     "news": [         {"posizioni": [             {"0": "allnews"},             {"1": "secondtab"},         ]}     ] }; 

in html, ng-repeat can this; because of json structure above gets little messy, gets job done:

<tab ng-repeat="(key, name) in data['news'][0]['posizioni']" heading="{{ tab.key }}" ng-click="selecttab($event, key, name)">{{ name[key] }}</tab> 

in fiddle added click handler show how can react click happened in tabcontroller update data in contentcontroller through service. note, contentservice contains array of data, update dynamically request content upstream server:

$scope.selecttab = function (event, key, name) {     contentservice.setcontent(key); } 

Comments