JavaScript AngularJS : $compile not working angularjs $compile not working,angularjs works compile,angularjs directive compile

In the following code, the $compile is not working. I have an item, I am adding this item to scope, so that I can compile this and get an html.

    $http({
            method: 'GET',
            url : url

        }).success(function(response) {
            // var data = response.data;
            $scope.item = preItem ;
            var e = $compile('<div>{{item.name}}</div>')($scope);

        });
    }

After that, I made every thing very static and event after that this didn't worked.

 $http({
            method: 'GET',
            url : url

        }).success(function(response) {

            $scope.tosenddata = 'testdata';
            var e = $compile('<div>{{tosenddata}}</div>')($scope);

        });
    }

Even after this the result was same!

I am doing this inside a controller.

Answer:1

In this case $compile is working and if you console the "e" it will show the angular's div element bind with ng-scope.

Now "e" is just a angular div element you need to insert it into the DOM to see the HTML or console e[0].

 $scope.tosenddata = 'testdata';
 var e = $compile('<div>{{tosenddata}}</div>')($scope);
 console.log(e[0]);  

In console you will see <div class="ng-scope ng-binding">testdata</div>

See console in this working fiddle

Thanks

Answer:2

I created a new vue project with the CLI and want to deploy it. Based on this documentation https://router.vuejs.org/guide/essentials/history-mode.html#html5-history-mode I added the history mode to ...

I created a new vue project with the CLI and want to deploy it. Based on this documentation https://router.vuejs.org/guide/essentials/history-mode.html#html5-history-mode I added the history mode to ...

I want to trying adding class using javascript, I know there is a lot of topic about this in stackoverflow but some of them is too complicated for me to understand, let say I have this simple code ...

I want to trying adding class using javascript, I know there is a lot of topic about this in stackoverflow but some of them is too complicated for me to understand, let say I have this simple code ...

  1. class javascript use strict
  2. javascript class using function
  3. javascript class using prototype
  4. class using javascript
  5. class in javascript
  6. class in javascript example
  7. javascript class with functions
  8. javascript class with constructor
  9. javascript class with properties
  10. javascript class with methods
  11. javascript class with multiple constructors
  12. javascript class with static methods
  13. javascript class with async function
  14. javascript class with array
  15. javascript class with variables
  16. javascript class with parameters
  17. javascript class in html
  18. javascript class in namespace
  19. javascript class with array property
  20. javascript class with arrow function

I have two variables with JSON files. The first is a list of keys looks like this: keylist = ["key1","key2","key3"] The second one is generated from a database and looks like this: data = { "...

I have two variables with JSON files. The first is a list of keys looks like this: keylist = ["key1","key2","key3"] The second one is generated from a database and looks like this: data = { "...

  1. access array with pointer c++
  2. access array with pointer
  3. access array with key javascript
  4. access array with index php
  5. access array with python
  6. access array of objects javascript
  7. access array in javascript
  8. access array in php
  9. access array of objects
  10. access array in matlab
  11. access array from another class java
  12. access array of json objects javascript
  13. access array in jquery
  14. access array in json
  15. access array by index javascript
  16. access array in c
  17. access array in dictionary python
  18. access array in struct c
  19. access array in java
  20. access array in scala

I have an array like below and I want to extract objects and sub-array and create a new array if the selected object value is true menu: [ { category_name: "snacks", selected: true ...

I have an array like below and I want to extract objects and sub-array and create a new array if the selected object value is true menu: [ { category_name: "snacks", selected: true ...