Search code examples
angularjskik

kik api wont work with angularjs json


I cant seem to make my angularjs code work with the kik api:

 var myApp = angular.module('myApp', []);
    myApp.controller('MainCtrl', function($scope) {

    $scope.go = function() {  
        kik.send({ 
            title: 'message title',
            text : 'Message body',
            data : {
                       color: 'green',
                       size: 'one'  }       
        });    
    }

    //kik.message is exactly what was provided in kik.send
    //in this case: { color: 'green', size: 'one' } 

    if(kik.message) {     
        $scope.result = kik.message;
    }   
});   

//html ng-app="my-app"
<div controller="MainCtrl">
    <li ng-repeat="todo in result">
        {{todo.color}} {{todo.size}}
    </li>
</div>

$scope.result should hold the data that was inside "api.oppened", but it seems like I made a mistake.

link to API


Solution

  • Looks like your ng-repeat expects result to be an array but it is instead { color: 'green', size: 'one' }. So when you do todo in result, todo isn't the object that you expect it to be.

    Simply change your assignment to result:

    if (kik.message) {
      $scope.result = [ kik.message ];
    }