I am brand new to Angular Js. I successfully retrieved data from golang in angular js. However, when I use it in an alert box, it displays as [object Object]. I attempted to fix this issue by changing the delimiters of golang from {{ }} to <<< >>>, but unfortunately, the problem persisted.
Here is my Go code (I am using beego):
func (receiver *AdsController) LoadNewCampaignPage() {
view := viewmodels.NewCampaignPageViewModel{}
view.Title = "New Campaign"
receiver.Data["vm"] = view
receiver.Layout = "layouts/ads_header.html"
receiver.TplName = "templates/ads_add_campaign.html"
}
The struct viewmodels.NewCampaignPageViewModel{}:
type NewCampaignPageViewModel struct {
Title string
ProfileName string
ProfilePicture string
UnUsedBoxes []models.Box
ErrorMessage string
}
HTML:
<div ng-controller="AddBoxForAdsCtrl">
<button class="_button _button-3" ng-click="showHiddenForm()">Add Box</button>
</div>
JavaScript:
var addBoxForAds = angular.module('addBoxForAds', []);
addBoxForAds.controller('AddBoxForAdsCtrl', function ($scope, $http){
var title = $http.get('<<<.vm.Title>>>'); //Data from GO; delimiters have been changed.
alert(title);
});
What mistakes have I made here? How can I effectively retrieve data from golang in angularjs? And how do I utilize the struct element UnUsedBoxes (which is an array of structs)?