2016-03-29 10 views
0

edit: Ich bin mit Bootstrap, denke ich Bootstrap Tab verursacht das Problem

Ansicht nicht nach $ scope Variable Update aktualisiert.

$ scope.codeData

wenn ich die $ scope.codeData trösten, ich die Daten sehen können, aber machen nicht in Sicht.

Ich muss zweimal klicken, um die Ansicht korrekt zu rendern.

ist irgendetwas mit meinem Code falsch?

Vielen Dank.

Config

angular.module('SPAroutes', ['ngRoute', 'SPAcontrollers', 'SPAdirectives']) 

.config(['$routeProvider', '$locationProvider', 
function($routeProvider, $locationProvider) { 
    $routeProvider 
    .when('/admin', { 
     templateUrl: 'templates/views/admin.html', 
     controller: 'adminCtrl', 
     controllerAs: 'admin' 
    }) 
    $locationProvider.html5Mode(true).hashPrefix('!'); 
}]); 

Controller.js

angular.module('SPAcontrollers', ['ngRoute', 'SPAfactories', 'SPAdirectives']).controller('adminCtrl', ['$scope', '$http', '$location', '$window', '$SPAaccount', function ($scope, $http, $location, $window, $SPAaccount) { 
    this.dataRetrive = function(category){ 
     $http.get('/ctrls/get/blockCode/header').then(function (res){ 
      $scope.codeData = res.data; 
      console.log($scope.codeData); 
      $('#headerTab').tab('show'); 
     }, function (err){ 
      console.log(err); 
     }) 
    }; 
}]); 

admin.html

{{codeData}}

+0

$ Umfang gelten $() wird die Arbeit tun.. Aber es sollte nicht benötigt werden. – atinder

+1

@atinder nein, das ist ganz sicher nicht die Antwort – Phil

+1

Wann/wo rufst du 'dataRetrieve()'? Sie scheinen auch '$ scope' mit' controllerAs' zu mischen, was normalerweise nicht das ist, was Sie wollen. – Phil

Antwort

1

Du Vertauschen controllerAs mit Rahmen als phil menti oned in seiner comment auf Frage. Anstatt den Bereich hier zu verwenden, speichern Sie Werte innerhalb von this auf etwas wie diese.

angular.module('SPAcontrollers', ['ngRoute', 'SPAfactories', 'SPAdirectives']).controller('adminCtrl', ['$scope', '$http', '$location', '$window', '$SPAaccount', function ($scope, $http, $location, $window, $SPAaccount) { 
    var admin = this; 
    this.dataRetrive = function(category){ 
     $http.get('/ctrls/get/blockCode/header').then(function (res){ 
      admin.codeData = res.data; 
      console.log(admin.codeData); 
      $('#headerTab').tab('show'); 
     }, function (err){ 
      console.log(err); 
     }) 
    }; 
}]); 

und in der Ansicht: admin.html

{{admin.codeData}} 

here arbeitet zupfen für Ihre refernce

Verwandte Themen