angularjs - Javascript controller -function is not defined -


i posted post wasn't easy read... hope 1 understand problem:

basicly have 2 controllers, , in first one, create dinamically div has 'onclick' attribute calls function on other controller (newcontroller). error is: activatesmartcase not defined.

i'm desperate lol.. help.

[edit solution]

var myinjector = angular.injector(["ng"]); var $http = myinjector.get("$http"); function funcb($http){ } 

manually getting http dependency.

app.controller('groupctrl', ['$scope','$http', '$resource',function($scope,$http,$resource) {       $scope.smartcase=function(){          $http.get('http://localhost:8080/userapi/getsmartcasesfromtype/' + elements[0].alt)         .then(function(result) {             $scope.smartcases = result.data;         });            var div = document.createelement("div");         div.setattribute('class', "container");         div.setattribute('id',elements[0].alt);         div.setattribute('ng-controller',"newcontroller");           div.setattribute('title',elements[0].id);         groupid=elements[0].id;         div.setattribute('alt',"smartcase");         div.setattribute('onclick', 'activatesmartcase()'); //here         var div2= document.createelement("div2");         div2.setattribute('class',"list-group");          div.appendchild(div2);          var = document.createelement("a");         a.setattribute('href',"#");         a.setattribute('class',"list-group-item active");          div2.appendchild(a);         for(var i=0; i<$scope.smartcases.length; i++) {              var h = document.createelement("h4");             h.setattribute('class',"list-group-item-heading");                           h.innerhtml=$scope.smartcases[i].type;             var p=document.createelement("p");             p.setattribute('class', "list-group-item-text");             p.innerhtml=$scope.smartcases[i].description;             a.appendchild(h);             a.appendchild(p);         }         document.body.appendchild(div);     }  }]); 
(function (){      'use strict';      angular     .module('myappgroup')     .controller('newcontroller', controller);      function controller($scope,$http,$resource){         const vm = this;         vm.activatesmartcase = function(){             //console.log(deviceid);             var operations=[];             $http.get('http://localhost:8080/userapi/listoperations/' + groupid)             .then(function(result) {                 operations = result.data;             });             console.log(operations);              var div = document.createelement("div");             div.setattribute('class', "dropdown");             var button=document.createelement("button");             button.setattribute('class', "btn btn-default dropdown-toggle");             button.setattribute('type',"button");             button.setattribute('id', "dropdownmenu1");             button.setattribute('data-toggle',"dropdown");             button.setattribute('aria-haspopup',"true");             button.setattribute('aria-expanded',"true");             var span=document.createelement("span");             span.setattribute('class',"caret");             button.appendchild(span);             div.appendchild(button);              var ul=document.createelement("ul");             ul.setattribute('class',"dropdown-menu");             ul.setattribute('aria-labelledby',"dropdownmenu1");              div.appendchild(ul);         }     }  })(); 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -