Javascript AngularJS-无法将范围值设置到模板中

Javascript AngularJS-无法将范围值设置到模板中,javascript,angularjs,scope,angularjs-scope,Javascript,Angularjs,Scope,Angularjs Scope,我有以下功能: $scope.setDetailToScope = function(data) { $scope.$apply(function() { //$scope.order = data; $rootScope.order = data; setTimeout(function() { $scope.$apply(function() { //wrapped this wi

我有以下功能:

$scope.setDetailToScope = function(data) {
    $scope.$apply(function() {
        //$scope.order = data;
        $rootScope.order = data;
        setTimeout(function() {
            $scope.$apply(function() {
                //wrapped this within $apply
                $scope.order = data[0];
                console.log('message:' + $scope.order);
                console.log($scope.order);
            });
        }, 100);
    });
};  
"

为我提供已设置为范围的值

但我无法在模板中获取这些值

<!-- DEBUG DIV -->
<div class="debugDiv" ng-show="$root.debugable == true">
 {{columns}}
</div>
<div data-ng-controller="OrdersCtrl" ng-init="initData()"> 
    <div id="orders_grid" >

    </div>
</div>
<!-- GRID TOOLBAR BUTTON TEMPLATE -->
<script id="template" type="text/x-kendo-template">
  <a class="k-button" href="\#/orders/create">Add</a>
</script>

<!-- ORDER DETAIL DIV -->
<div class="container" id="orderDetail" data-ng-controller="OrdersCtrl"  ng-if="'detailSelected == true'" xmlns="http://www.w3.org/1999/html">
    <!-- DEBUG DIV -->
    <div class="debugDiv" ng-show="$root.debugable == true">
      {{order}} <!--NOT WORKING-->
   </div>

我不知道为什么要使用范围为apply的setTimeout,对我来说使用更安全,因为它会触发另一个摘要循环

试试像这样的东西

$scope.setDetailToScope = function(data) {
    $timeout(funtion(){
        //$rootScope.order = data; try either data or data[0]
        $scope.order = data[0];

    },100);
};  
请注意,调用嵌套的apply方法可能会在angularjs摘要循环中遇到一些问题,您可能会遇到类似“”的错误,所以请注意它

注意:

看起来那里有一些脏数据,所以尝试在数据和范围之间做一个映射

$scope.order ={};
$scope.order.uid = data.uid;
$scope.order.orderNumber = data.orderNumber //and so on
在模板中,尝试以下操作:

 <div class="debugDiv">
     <p> {{order.uid}} </p>
     <p> {{ order.orderNumber}} </p>
   </div>

{{order.uid}

{{order.orderNumber}


这可能有点粗俗,但值得一试。

您能提供一个JSFIDLE吗?请使用数据[0]进行尝试或者数据,删除ng如果你只是为了调试的目的而输入了详细信息,试着做一个控制台日志,检查你在作用域或根作用域上得到了什么我试着用静态值来构思,在console.log中似乎可以,但模板中没有显示任何内容。但是如果我在表单输入中手动插入一些值,则在作用域中会出现值..是str吗ange.DOM中是否有元素?是否可以尝试删除ng if=“'detailSelected==true”和ng show=“$root.debugable==true”,仅用于检查与您为DOM实现的条件无关
$scope.order ={};
$scope.order.uid = data.uid;
$scope.order.orderNumber = data.orderNumber //and so on
 <div class="debugDiv">
     <p> {{order.uid}} </p>
     <p> {{ order.orderNumber}} </p>
   </div>