JavaScript ng-click not firing $scope.doSomething(), onclick for same function works

The controller I'm using is:

angular.module('app.PostView', [])

.controller('PostViewCtrl', function($scope, $http, Constants) {


    $scope.posts = [];      
    $scope.doSomething = function(){
        console.log("in doSomething");
    }

    $http.get(Constants.POST_URL)
        .then(function (response){
            console.log(response);

            var post = new PostFactory(response.data);

            $scope.posts.push(post);



        });


})

The view for the controller is

<div ng-repeat="post in posts" >
  <div class="home-container">
    <div id="details-container">
          <!-- using single item Array instead of single iftem to fix linkify bug -->
        <div ng-bind="post.desc"></div>
        <span class="item-note single-post-details">
          <!-- <div class="time-text">{{post.id}}</div> -->
          <div class="title" >{{post.title}}</div>
        </span>
        <a ng-click="doSomething()" target='_blank' href="#" >{{post.name}}</a>
    </div>
  </div>
</div>

If I replace ng-click with onclick then doSomething is triggered. Currently it is not. The same Controller and html code in other controller/views does work.

Answer:1

When you clicking on the anchor, it change the routing as http://url/#, that listen by the $routeProvider & ng-view loads the default view and template as you are seeing on your side.

Basically you need to remove target='_blank' href="#" from your anchor link or just put target='_blank' href="" blank in that anchor. That would fix your problem.

 <a ng-click="doSomething()" target='_blank' href="" >{{post.name}}</a>
Answer:2

I want to delete "()" from each value. How would I do that? var arr = ["(one)","(two)","(three)","(four)","(five)"]; for(var i = 0; i < arr.length; i++){ console.log(arr[i]); }

I want to delete "()" from each value. How would I do that? var arr = ["(one)","(two)","(three)","(four)","(five)"]; for(var i = 0; i < arr.length; i++){ console.log(arr[i]); }

  1. javascript trim characters from end
  2. javascript trim character from start
  3. javascript trim characters from beginning of string
  4. javascript trim character from start and end
  5. javascript trim character length
  6. javascript trim character limit
  7. javascript trim last character
  8. javascript trim first character
  9. javascript trim specific character
  10. javascript trim after character
  11. javascript trim right character
  12. javascript trim special characters
  13. javascript trim last character if comma
  14. javascript trim last character of string
  15. javascript trim first character from string
  16. javascript trim custom characters
  17. javascript trim other characters
  18. javascript trim last character if slash

I have been trying to parse nested JSON data and below is my code var string = '{"key1": "value", "key2": "value1", "Key3": {"key31":"value 31"}}'; var obj = JSON.parse(string); console.log(obj.key1) ...

I have been trying to parse nested JSON data and below is my code var string = '{"key1": "value", "key2": "value1", "Key3": {"key31":"value 31"}}'; var obj = JSON.parse(string); console.log(obj.key1) ...

  1. parsing nested json in python
  2. parsing nested json in javascript
  3. parsing nested json in java
  4. parsing nested json data in javascript
  5. parsing nested json c#
  6. parsing nested json swift
  7. parsing nested json golang
  8. parsing nested json in vba
  9. parsing nested json in spark
  10. parsing nested json in node js
  11. parsing nested json in flutter
  12. parsing nested json array in java
  13. parsing nested json using jackson
  14. parsing nested json with pandas
  15. parsing nested json in pyspark
  16. parsing nested json logstash
  17. parsing nested json in java using jackson
  18. parsing nested json objects in python
  19. parsing nested json in swift 4

I am self taught PHP with little js experience so it is probably something really simple, but I have made a js function to change the inner html of a table cell and added an onchange event listener on ...

I am self taught PHP with little js experience so it is probably something really simple, but I have made a js function to change the inner html of a table cell and added an onchange event listener on ...

  1. change inner html jquery
  2. change innerhtml javascript
  3. change inner html css
  4. change innerhtml onclick
  5. change inner html with php
  6. change innerhtml
  7. javascript change innerhtml
  8. change innerhtml using jquery
  9. change innerhtml of div
  10. angular change innerhtml
  11. change inner html of span
  12. react change innerhtml
  13. jquery change innerhtml of div
  14. change innerhtml of element
  15. change innerhtml on click jquery
  16. change innerhtml text
  17. change innerhtml using javascript
  18. change innerhtml of class
  19. change innerhtml of label
  20. function change innerhtml

<div class="js-show-more"> <p class="app-light-text"> The factors of a number are all the numbers that divide into it. The highest common factor, HCF, of two or more ...

<div class="js-show-more"> <p class="app-light-text"> The factors of a number are all the numbers that divide into it. The highest common factor, HCF, of two or more ...

  1. change class element angular
  2. add class element angular 2
  3. add class element angular
  4. add class element angularjs
  5. add class element angular 5
  6. angular remove class from element
  7. get element class angular
  8. remove element class angular 2
  9. native element class angular
  10. get element class angular 2
  11. remove class angular element
  12. get element class angularjs
  13. change element class angularjs
  14. dom element class angular2
  15. add class to element angular 6
  16. add class to element angular 4
  17. add class to element angular 7
  18. remove class from element angular 6
  19. set class to element angular
  20. add class to element angular 8