AngularJS [SOLVED]: getting undefined when using wordpress post meta with underscore in angularjs

AngularJS [SOLVED]: getting undefined when using wordpress post meta with underscore in angularjs

Home Forums Frameworks AngularJS tutorials AngularJS [SOLVED]: getting undefined when using wordpress post meta with underscore in angularjs

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246242

    Cloudy Point
    Keymaster

    QuestionQuestion

    i am using wordpress rest api v2 for getting data from my working wordpress website to angularjs application. all is working fine but when i want to use post meta like “_ait-item_item-data”. its return me an error “undefined”.

    i am using his code to get post meta :

    $scope.fieldOne = $scope.businessDetails.post_meta_fields._ait-item_item-data;
    

    and i want to print:

    {{fieldOne}}
    

    i know that the problem with underscore and hyphen but how can i get the meta data with them ?

    this is the error in console:

    ReferenceError: item_item is not defined
    at itemSingleCtrl.js:13
    at angular.js:16170
    at m.$eval (angular.js:17444)
    at m.$digest (angular.js:17257)
    at m.$apply (angular.js:17552)
    at l (angular.js:11697)
    at K (angular.js:11903)
    at XMLHttpRequest.y.onload (angular.js:11836)
    

    #246243

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    Since your property contains - in it, you can’t use dot notation to access its value. You have to access it like below

    $scope.fieldOne = $scope.businessDetails.post_meta_fields["_ait-item_item-data??"]
    

    Source: https://stackoverflow.com/questions/47968734/getting-undefined-when-using-wordpress-post-meta-with-underscore-in-angularjs
    Author: Vipin Kumar
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.