myular“>中的AngularJs <div ng-repeat =”(键,数据)在使用$ ionicPopup.alert的控制器中不起作用

时间:2015-10-05 13:01:41

标签: angularjs ionic

**错误:[$ parse:syntax]语法错误:令牌'对象'是意外的,期望[[object]]的第9列的[]开始于[Object]]。 http://errors.angularjs.org/1.3.13/ $ parse / syntax?p0 =对象&amp; p1 =是%20unexpected%2C%20expecting%20%5B%5D%5D&amp; p2 = 9&amp; p3 =%5Bobject“”

.controller('AppCtrl', function($scope,$ionicPopup,$state ) {

     $scope.myData = { prop1: "val1", prop2: "val2", prop3: "val3",prop4: "val4" };
                       var alertPopup =$ionicPopup.alert({

                    //templateUrl: '/templates/view.html'
                       template:
                           '<div class="row list-inset" ng-repeat= "(key, data) in '+$scope.myData+'" >'+
                         '<div class="col font_type2" >{{key}}</div>'+
                         '<div class="col font_type2" >{{data}}</div>'+
                         '</div>'

                      });
});

2 个答案:

答案 0 :(得分:1)

您的问题是使用String将$ scope.myData(Object)连接起来。当这个Js将$ scope.MyData解释为$ scope.MyData.toString()时,它返回&#34; Object&#34;。对于使用String连接后修复可序列化的$ scope.MyData。

对于可序列化的用途:angular.element($ scope.myData).serialize();

.controller('AppCtrl', function($scope,$ionicPopup,$state ) {
    $scope.myData = { prop1: "val1", prop2: "val2", prop3: "val3",prop4: "val4" };
    var alertPopup =$ionicPopup.alert({
        //templateUrl: '/templates/view.html'
        template:
        '<div class="row list-inset" ng-repeat= "(key, data) in '+angular.element($scope.myData).serialize()+'" >'+
        '<div class="col font_type2" >{{key}}</div>'+
        '<div class="col font_type2" >{{data}}</div>'+
        '</div>'
    });
});

答案 1 :(得分:1)

  

$ scope,因此他们可以将其指定为弹出窗口中的scope属性   数据绑定弹出窗口的选项和范围。

.controller('AppCtrl', function($scope,$ionicPopup,$state ) {

     $scope.myData = { prop1: "val1", prop2: "val2", prop3: "val3",prop4: "val4" };
                       var alertPopup =$ionicPopup.alert({

                       scope: $scope,       // define the scope is here.

                       //templateUrl: '/templates/view.html'
                       template:
                           '<div class="row list-inset" ng-repeat= "(key, data) in '+$scope.myData+'" >'+
                         '<div class="col font_type2" >{{key}}</div>'+
                         '<div class="col font_type2" >{{data}}</div>'+
                         '</div>'

                      });
});