{"action":"closed","issue":{"url":"https://api.github.com/repos/angular-ui-tree/angular-ui-tree/issues/593","labels_url":"https://api.github.com/repos/angular-ui-tree/angular-ui-tree/issues/593/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui-tree/angular-ui-tree/issues/593/comments","events_url":"https://api.github.com/repos/angular-ui-tree/angular-ui-tree/issues/593/events","html_url":"https://github.com/angular-ui-tree/angular-ui-tree/issues/593","id":107377221,"number":593,"title":"if the tree is empty, how can i add a new node by program?","user":{"login":"subjectwa","id":1276585,"avatar_url":"https://avatars.githubusercontent.com/u/1276585?v=3","gravatar_id":"","url":"https://api.github.com/users/subjectwa","html_url":"https://github.com/subjectwa","followers_url":"https://api.github.com/users/subjectwa/followers","following_url":"https://api.github.com/users/subjectwa/following{/other_user}","gists_url":"https://api.github.com/users/subjectwa/gists{/gist_id}","starred_url":"https://api.github.com/users/subjectwa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/subjectwa/subscriptions","organizations_url":"https://api.github.com/users/subjectwa/orgs","repos_url":"https://api.github.com/users/subjectwa/repos","events_url":"https://api.github.com/users/subjectwa/events{/privacy}","received_events_url":"https://api.github.com/users/subjectwa/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-20T07:09:07Z","updated_at":"2015-09-24T03:40:02Z","closed_at":"2015-09-24T03:40:02Z","body":"I can use the follow code to add a node to the tree on 1-level if the tree is not empty\r\n<pre><code>\r\nvar newData = {title:'test'};\r\nvar uiTreeScope = angular.element('[ui-tree]').scope();\r\nif (uiTreeScope.$nodesScope.$modelValue.length > 0)\r\n    uiTreeScope.$nodesScope.$modelValue.push(newData);\r\n</code></pre>\r\nbut if the tree is empty,it will get this error:\r\n<pre><code>\r\nuiTreeScope.$nodesScope.$modelValue is undefined\r\n</code></pre>\r\nthen i try the follow\r\n<pre><code>\r\nif(angular.isUndefined(uiTreeScope.$nodesScope.$modelValue)) {\r\n   uiTreeScope.$nodesScope.$modelValue = [];\r\n   uiTreeScope.$nodesScope.insertNode(0,newData);\r\n}\r\n</code></pre>\r\nthere is no error,but the tree isn't show up,so what's the solution?"}}