数据显示在控制器和服务中,但未显示在视图中

时间:2016-08-28 05:59:28

标签: angularjs redis electron

view - index.html它将以ng-repeat

打印数据
      <!DOCTYPE html>
       <html>

    <head>
      <meta charset="UTF-8">
      <title>hii</title>
      <script src="bower_components/angular/angular.js"></script>


    </head>

    <body ng-app="myApp" ng-controller="myCtrl">
      <h1>wellcom </h1>


      <p ng-repeat="d in data1 track by $index">{{d}}</p>

      <!--<h3 ng-repeat="d1 in data2"> Type Of data are:  {{d1}}</h3>-->

       </body>

    <script src="controller.js">
        </script>

    <script src="service.js">
        </script>

    </html>

这是我的服务,我将一些数据类型设置为Redis服务器,然后检索该数据类型并将数据返回给控制器。

var Promise = require("bluebird");
var redis = Promise.promisifyAll(require("redis"));
var client = redis.createClient();

angular.module('myApp')
    .service('redisService', function ($q) {

        this.getAll = function () {
            var a1 = [];
            return $q(function (resolve, reject) {
                //    client.set("string key", "string val", redis.print);
                //     client.hset("hash name", "hashkey 1", "some value", redis.print);
                //     client.hset("hash name", "hashkey 2", "some other value", redis.print);
                //     client.lpush("mylist", "In", redis.print);

                client.scanAsync(0).then(function (data) {

                    data[1].forEach(function (reply) {
                        client.typeAsync(reply).then(function (a) {
                            a1.push(a);


                        })
                    })



                });

                return resolve(a1);
            })

        }

    });

这是我的控制器在这个数据来了并打印到控制台但是数据没有设置查看,即没有显示到index.html

angular.module('myApp', [])
    .controller('myCtrl', function ($scope, redisService, $q) {

        $scope.data1;
        redisService.getAll().then(function (data) {
            $scope.data1 = data;
            console.log('data is', $scope.data1)
        })

    })

0 个答案:

没有答案
相关问题