0

I have an html file and I want to show on it information from mongoDB. I want to show all the messages that are in the mongoDB. I build an html page that expect to information:

<div class="jumbotron text-center">
    <h1>List</h1>
    <br><br>

    <button ng-click="showAllButton()">Show All</button>
    <br> <br>

    <p>{{ tagline }}</p>

    <label for="messageName">Message Name:</label>
    <input type="text" style="width:50%; float:center" ng-model="message.name"  name="message.name" readonly/>
    <br/><br/>

    <label for="text">Text:</label>
    <input type="text" style="width:50%" ng-model="message.text" name="message.text" readonly/>
    <br/><br/>

    <label for="images">Images:</label>
    <input type="text" style="width:50%" ng-model="message.images" name="message.images" readonly/>
    <br/><br/>

    <label for="template">Template:</label>
    <input type="text" style="width:50%" ng-model="message.template" name="message.template" readonly/>
    <br/><br/>

    <label for="millisecToShow">Millisec To Show:</label>
    <input type="text" style="width:50%" ng-model="message.millisecToShow" name="message.millisecToShow" readonly/>
    <br/><br/>

    <label for="timeFrame">Time Frame:</label><br>
    <label for="TimeStart">Start Time:</label>
    <input type="text" style="width:50%" ng-model="message.startDateTime" name="message.startDateTime" readonly/>
    <br/><br/>
    <label for="DateStart">End Time:</label>
    <input type="text" style="width:50%" ng-model="message.endDateTime" name="message.endDateTime" readonly/>
    <br/><br/>

    <label for="days">Days:</label><br>
    <input type="text" style="width:50%" ng-model="message.days" name="message.days" readonly/>
    <br/><br/>

    <label for="screenId">Screen ID:</label>
    <input type="text" style="width:50%" ng-model="message.screenId" name="message.screenId" readonly/>
    <br><br>

    <button ng-click="nextMsg()">Next</button>
    <button ng-click="previousMsg()">previous</button>
    <br><br>

</div>

and I have that controller to do it:

angular.module('ListCtrl', []).controller('ListController', function($scope, superService) {

var index = 0;

    $scope.showAllButton = function() {
        superService.list().then(function (result) {

            if ((result != "false") && (result != undefined)) {
                index = 0;

                $scope.tagline = result;
                $scope.message.name = result[index].messageName;
                $scope.message.text = result[index].text;
                $scope.message.images = result[index].images;
                $scope.message.template = result[index].template;
                $scope.message.millisecToShow = result[index].millisecToShow;
                $scope.message.startDateTime = result[index].timeFrame[0].date.start + ". Time: " + result[0].timeFrame[0].time.start.hour + ":" + result[0].timeFrame[0].time.start.minutes;
                $scope.message.endDateTime = result[index].timeFrame[0].date.end + ". Time: " + result[0].timeFrame[0].time.end.hour + ":" + result[0].timeFrame[0].time.end.minutes;;
                $scope.message.days = result[index].timeFrame[0].days;
                $scope.message.screenId = result[index].screenId;
            }
            else {
                $scope.tagline = 'No messages';
            }
            return result.data;
        });
    };

The information that I get from the DB is fine. but that informtion don't shown in the textboxs, the error is: "TypeError: Cannot set property 'name' of undefined". $scope.message is undefined. someone can please tell me why and how I fix this? thanks (:

0

1 Answer 1

1

$scope.message is undefined so you have to define it. e.g.:

$scope.message = {};
$scope.message.name = result[index].messageName;
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.