0
votes

I'm new to SAPUI5 and I'm trying to set a value into a label in my view via my controller.

View1.controller.js

onInit: function()
        {
            var currentTime = this.whatsTheTime();
            var currentDate = this.whatsTheDate();
            this.getView().byId("timeDisplay").setValue(currentTime);
            this.getView().byId("dateDisplay").setValue(currentDate);

                this.repeat(function() {
                        currentTime = this.whatsTheTime();
                        currentDate = this.whatsTheDate();
                        this.getView().byId("timeDisplay").setText(currentTime);
                        this.getView().byId("dateDisplay").setText(currentDate);
                }, 1000);

view.xml

<mvc:View controllerName="testApp.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
    <Label  id = "timeDisplay" design="Bold" />
    <Label  id = "dateDisplay" design="Bold"/>
    <Button
        text = "Click me"
        press = "doNothing"  />
</mvc:View>

Basically, in the controller, whatsTheTime and whatsTheDate both return values and I'm trying to set those values into the label. It's a pretty simple thing but I'm missing out something because in my console

this.getView(...).byId(...).setValue is not a function

EDIT: Also, is there any particular way in writing my repeat function to run every 1 second inside my onInit function? Because it says that repeat is not a function. The whole point of the repeat function is to update the value every 1 second.

Why exactly is this throwing me up this error?

1

1 Answers

2
votes

Label does not have a Value property, so there is no setValue function (which is reported in error text), but it has "text" property, so you should do:

this.getView(...).byId(...).setText( ... )