on 2023 Mar 13 6:55 AM
Request clarification before answering.
Hi Luis,
the error message already indicates it: TypeScript does not find these methods on UI5Element (which stands for the sap.ui.base.Element base class of all Controls etc.).
The TypeScript compiler simply is not aware that this.byId(...) returns an IconTabHeader. It cannot know this, as the returned control type depends on the ID which you give as argument (and there is no functionality which searches the id in the XMLView and tells TypeScript what kind of control has this ID).
The solution is to cast the result of this call to the control type you know is returned:
(this.byId("idIconTabBar") as IconTabBar).getSelectedKey()
This is commonly done in the tutorial and samples linked from the central UI5 & TypeScript entry point (https://sap.github.io/ui5-typescript), so I guess it makes sense to mention this page for those who are getting here and not aware of it.
Regards
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This error is because `byId` returns a `UI5Element` (a base class from which all view controls extend), and that doesn't have the methods you are trying to call. Try casting the element to the control class you are actually using in the view.
const iconTabHeader = this.byId('idIconTabHeader') as IconTabHeader
switch(iconTabHeader.getSelectedKey()) { ... }
For the `setVisible` method it should cast as at least the 'Control' class.
const c = this.byId('id') as Control
c.setVisible(true)
It works in the console because that's pure javascript, which is less strict than typescript. In reality your code could run without any errors, but typescript doesn't allow you to compile the code without checking types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Luis Frey
This error indicates that you have used a property that does not exist in the type of object you are trying to access. Check the object type you are accessing and make sure the property you are trying to access is defined for that type. If it is not, you will need to either change the property you are trying to access or the type of object you are trying to access.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi yoganandamuthaiah ,
thanks for your quick reply.
i checked it again:
https://sapui5.hana.ondemand.com/#/api/sap.m.IconTabHeader%23methods/Summary
User | Count |
---|---|
52 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.