Search code examples
angularjsdojoibm-mobilefirst

dijit.byId("").is not defined in Worklight works with Angularjs


I make a project in worklight used dojo mobile 1.8.1 and angularjs 1.0.1,but i got a strange problem.

Here is my html part:

<div data-dojo-type="dojox.mobile.ScrollableView" data-dojo-props="selected:true"  id="id1" ></div>

<div class="full" data-dojo-type="dojox.mobile.View" id="id2"></div>

and my JavaScript part:

require([
"dojo", "dijit/_base/manager","dojo/parser", "dijit/registry",
], function(dojo) {
dojo.ready(function() {

// dijit.byId("id1").performTransition("id2");   //////////place I

});
});


var angularApp = angular.module('app', [])
.run(['$rootScope','$templateCache','$route',
  function($rootScope,$templateCache,$route) {

dijit.byId("id1").performTransition("id2");////////place II
}]);

The problem is at place I, it works well, but when I put "dijit.byId("id1")" at place II, it shows:

dijit.byId("").is not defined


Solution

  • The ready function is executed after dojo parsed your document & constructed the widgets you try to get using dijit.byId.

    The second part is not placed within the ready function, so dojo can't find your elements yet !

    Solution: Access your elements in the ready function OR do not declare them declaratively (like you did, using html code...) !

    Lucian