Getting a point value without an endless loop
-
Hi everyone!
I'm a new worker with Mango and I'm trying to write my own module. I want to get a latest value of a data point, but I found only a way to get a point (not a value). Is there a function to get a value? I tried to find a syntax for the component <ma-get-point-value> but I could not..
My code for getting point is:$scope.getPoint = (city, block) => { maPoint.query({rqlQuery: "eq(tags.City,"+city+")&eq(tags.Block,"+block+")"}).$promise.then((points) => { $scope.blockPoints = points; }) document.getElementById("block").innerHTML = $scope.blockPoints[0].xid; }
I also tried to get point value through $http.get. I got the value, but my page went into an endless loop.. And I don't understand how to stop it (and why it continues).
My code with $http.get is:$scope.pointValue = [] $scope.getPrumer = () => { $http.get(`https:///localhost:8080/rest/v2/point-values/latest/xid?fields=VALUE&limit=1`).then(response => { $scope.pointValue = response.data; }); document.getElementById("value").innerHTML = $scope.pointValue[0].value; }
Please help me understand what I'm doing wrong.
-
@ms_brunette Welcome to the forum!
In the angular js world, you don't need document.getElementById, you'd useangular.element('#id')
angular.element(document.getElementById(id))
which is a subset of jquery.Also I'd recommend looking at the docs and examples for using the various directives. Activate it by turning it on in the edit menu under administration then saving.
Also, if you know how angular works and are aware of how to make controllers and components use maPoint to do point queries. For values however, use maPointValues.
Refer to their github repo for MangoAutomation under the https://github.com/MangoAutomation/ma-dashboards to see how the services and directives works.
If you're still stuck I'll be able to help more in about a day or so
Fox
-
@ms_brunette here's an old post I wrote highlighting how to make a component with the user module addon
https://forum.mango-os.com/topic/3720/pop-up-window-face-plate/12?_=1713211779825Fox
-
@MattFox Thank you for answering! Actually, I already won this battle, but apparently there is a whole war ahead :D
I didn't understand all the behavior, but I found a working solution for my case.
Regarding your comments - in my environment angular.element('#id') doesn't work by some reasons, and I still don't know how to write maPointValues correctly..
Thanks for the link. I found it very useful! -
@ms_brunette you're welcome! Always happy to help. Also, my apologies, angular.element(htmlelrnent), I misunderstood the jqlite reference.
So HTML string or DOMElement should be the value in the element method. It will return a jQuery object.
https://docs.angularjs.org/api/ng/function/angular.elementFeel free to post another forum question if you are unable to find a solution via the search box.
Fox