cancel
Showing results for 
Search instead for 
Did you mean: 

MessageToast.show is not a function, although sap/m/MessageToast has already been imported.

Former Member

hello,

I would like to display a messager in sapui5 Application, when onSave is printed or at the init function ist started. but i have always a error in the console and the messageToast do not work.

Errormessage in console:

Uncaught (in promise) TypeError: MessageToast.show is not a function

this is my controller.js:

sap.ui.define(['sap/ui/core/mvc/Controller', 
	'timeTrackertimeTracker/controller/BaseController', 
	'sap/ui/model/json/JSONModel', 
	"sap/m/MessageToast",
	"sap/ui/model/odata/ODataModel",
	"sap/ui/core/routing/History"
	],




    	function(Controller, BaseController, MessageToast, JSONModel, ODataModel, History) {
    	"use strict";


    	//Global variables
    	//var _oController, oModel, oView;
    	var Calendarcontroller = BaseController.extend("timeTrackertimeTracker.controller.Calendarform", {
    	
		/* =========================================================== */
		/* lifecycle methods                                           */
		/* =========================================================== */


    		
		onInit: function() {
				//Store controller reference to global variable
				this.getRouter().getRoute("Calendarform").attachPatternMatched(this._onRouteMatched, this);
				MessageToast.show("init");
		}, 
				


		
		/* =========================================================== */
		/* event handlers                                              */
		/* =========================================================== */
		
		_onRouteMatched: function() {
			// register for metadata loaded events
			var oModel = this.getModel("appointments");
			oModel.metadataLoaded().then(this._onMetadataLoaded.bind(this));
		},
		
		_onMetadataLoaded: function () {
			// create default properties
			 var oProperties = {
				Id: "Id" + parseInt(Math.random() * 1000000000)
/*				duration: "",
				resttime: "",
				title: "",
				starttime: "",
				endtime: "",
				Description: ""*/
			};


			// create new entry in the model
			this._oContext = this.getModel("appointments").createEntry("/appointments", {
				properties: oProperties
				,
				success: this._onCreateSuccess.bind(this)
			});


			// bind the view to the new entry
			this.getView().setBindingContext(this._oContext, "appointments");


			


		},
		
		onSave: function(oEvent) {
			
          
			// bind the view to the new entry
			//this.getView().setBindingContext(this._oContext);


			this.getModel("appointments").submitChanges();
		
		}, 
		
		_onCreateSuccess: function (oEvent) {
			// navigate to the new product's object view
			this.getRouter().navTo("AppointmentsList", true);
	
			// unbind the view to not show this object again
			this.getView().unbindObject();
			
			// show success messge
/*			var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oEvent.Id ]);
			MessageToast.show(sMessage, {
				closeOnBrowserNavigation : false
			});*/
		},
		


/*		_onCreateSuccess: function (oAppointment) {
			// show success messge
			var sMessage = this.getResourceBundle().getText("newObjectCreated", [ oAppointment.Title ]);
			MessageToast.show(sMessage, {
				closeOnBrowserNavigation : false
			});
		},
		*/


		onCancel: function() {
			this.onNavBack();
			//this.getView().getModel("appointments").deleteCreatedEntry(this._oContext);
		},
		
		
		/**
		 * Event handler for navigating back.
		 * It checks if there is a history entry. If yes, history.go(-1) will happen.
		 * If not, it will replace the current entry of the browser history with the worklist route.
		 * @public
		 */
		onNavBack : function() {


/*			var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
			oRouter.navTo("AppointmentsList");*/
			
			
			var oHistory = History.getInstance(),
				sPreviousHash = oHistory.getPreviousHash();


			// discard new product from model.
			this.getModel("appointments").deleteCreatedEntry(this._oContext);


			if (sPreviousHash !== undefined) {
				// The history contains a previous entry
				history.go(-1);
			} else {
				// Otherwise we go backwards with a forward history
				var bReplace = true;
				this.getRouter().navTo("AppointmentsList", {}, bReplace);
			}
		}


    	});
     
    	return Calendarcontroller;
     
    });

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor

hi

this

function(Controller, BaseController, MessageToast, JSONModel, ...

should be

function(Controller, BaseController, JSONModel, MessageToast, ...

Thanks

-D

Noufal
Explorer
0 Kudos

Hello,

Please change the defition of your controller :

function(Controller, BaseController, JSONModel, MessageToast, ODataModel, History)

Answers (1)

Answers (1)

Former Member
0 Kudos

that worked, thank you!