HOW to properly Add a Dynamic View e.g WebView



i tried this but it throws an error “Wv.addChild(wv) is not a function”
var wv = new webViewModule.WebView(); wv.src = ""; var Wv = page.getViewById('wbv'); Wv.addChild(wv);
Please help @manojdcoder


To which component you are actually trying to add the newly created WebView? wbv must be a layout for your code to work.


yes it is a Gridlayout, i tried stacklayout still throws error, its like addChild() doesn’t exist anymore in {N} 3.4.3 can you pliz show how its done in playground! because i spent 5hrs in Playground to no avail, even the playground editor(or VS code editor) doesn’t auto complete the addChild() function


It seems to work perfectly fine, you may refer the example by @multishiv19 which is also listed in NativeScript Snacks.

If you still face issues, I would recommend you to share your example where we can reproduce the issue.


here is the solution How to Add Dynamic Views i found out that you CAN’T add a dynamic view if the View Element(parent) is empty, if you see in my snack from playground, the Gridlayout has a child Lable(it could have been anything) without which it Throws an error

<Page loaded="pageLoaded" class="page" navigatedTo="navigatingTo" xmlns="">

	<ActionBar title="Home" class="action-bar">
	<GridLayout id="wv">
		<Label/>//this one  will be replaced by the WebView i think


As it’s a GridLayout, did you try designated methods there?




The point is i am adding the dynamic view(WebView) into the Gridlayout which is declared in xml, if there is no other view in the Gridlayout an error is thrown but if there is something else it works!!!