aframe physics collision event not detected in angular controller - angularjs

I am trying to detect a collision event between a dynamic body and a static body and using Don Mccurdy's physics system.
The "collide" event is getting successfully invoked on collision but the subsequent function fails with the error "cannot read property 'body' of undefined for e"
My HTML source
<div ng-app="webVrApp">
<div ng-controller="trying">
<a-scene physics="debug: true">
<a-entity id='ball' position="0 1 -4" material="color:green;"
geometry="primitive:sphere; radius: 0.5;" dynamic-body></a-entity>
<a-plane color='red' static-body rotation="-90 0 0" width="100"
height="100"></a-plane>
<a-entity camera look-controls position="0 1.5 0">
<a-cursor></a-cursor>
<a-entity position="0 0 -3" id="weapon" static-body>
<a-box color='blue' width='0.25' height='0.5' depth='3' static-
body></a-box>
</a-entity>
</a-entity>
</a-scene>
</div>
</div>
and the controller code
app.controller('trying', ['$scope', function($scope){
var $ = function (sel){document.querySelector(sel)};
document.querySelector('#weapon').addEventListener('collide', function(e) {
const ball = $("#ball");
if(e.detail.body.id === ball.body.id) { //error comes for this line unknown 'body'
alert("collision happened");
};
});
}]);
Here is a codepen for this - codepen
Please help.

I'm using aframe-aabb-collider-component to detect colision between two objects, try it. https://www.npmjs.com/package/aframe-aabb-collider-component

Related

angularjs limit html editor data to some limit

Here is response that i am getting from Api
data :
<style type="text/css">
<!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}-->
</style>
<span style="font-size:11pt;font-family:Calibri,Arial;font-style:normal;color:#000000;"
data-sheets-value="{"1":2,"2":"http://www.gov.ph/2001/08/11/republic-act-no-9155/\n\n\nhttp://deped.gov.ph/orders/do-13-s-2016\n\n\n\n\n\n\n\nhttp://www.gov.ph/1991/10/10/republic-act-no-7160/"}"
data-sheets-userformat="{"2":2112445,"3":[null,0],"5":{"1":[{"1":2,"2":0,"5":[null,2,0]},{"1":0,"2":0,"3":3},{"1":1,"2":0,"4":1}]},"6":{"1":[{"1":2,"2":0,"5":[null,2,0]},{"1":0,"2":0,"3":3},{"1":1,"2":0,"4":1}]},"7":{"1":[{"1":2,"2":0,"5":[null,2,0]},{"1":0,"2":0,"3":3},{"1":1,"2":0,"4":1}]},"8":{"1":[{"1":2,"2":0,"5":[null,2,0]},{"1":0,"2":0,"3":3},{"1":1,"2":0,"4":1}]},"10":1,"11":4,"12":0,"14":[null,2,0],"15":"Calibri","16":11,"24":[null,0,3,0,3]}"
>http://www.gov.ph/2001/08/11/republic-act-no-9155/<br>
<br><br>http://deped.gov.ph/orders/do-13-s-2016<br>
<br><br><br><br><br><br>
<br>http://www.gov.ph/1991/10/10/republic-act-no-7160/
</span>"
All above is data i am getting from api
so i just want show 300 character then ....
For show more or less function
Please help
Thanks in advance
Try this.
Your HTML
<div ng-app="yourAppName">
<div ng-controller="YourControllerName">
<p ng-show="showLink">{{lngStr|limitTo:300}}
show more
</p>
<p ng-hide="showLink">{{lngStr}}
hide
</p>
</div>
</div>
Your Controller
angular.module("yourAppName", ["your", "dependencies"])
.controller("YourControllerName", function ($scope) {
$scope.lngStr = the_Very_Long_String_You_Retrieve_From_Your_Api;
$scope.showLink = true; // Set the showLink to show onLoad
$scope.showMore = function () {
$scope.showLink = !$scope.showLink;
}
})
I'll edit this into a plunker when I have a better internet connection.

uib-carousel has height 0

Using:
angularjs 1.5.3
ui-bootstrap 1.3.2
This is my template:
<div id="content" class="center">
<div id="title">
<uib-carousel active="true" interval="5000" ng-if="slides && slides.length">
<uib-slide ng-repeat="slide in slides track by slide.name">
<img ng-src="{{ slide.image }}" />
<div class="carousel-caption">
<p>{{ slide.description }}</p>
</div>
</uib-slide>
</uib-carousel>
</div>
</div>
Somewhere in my code I perform a call (with a working service I used many times) like this:
Index.controller('Index.Main', ['$scope', '$sce', 'MyService', function($scope, $sce, myService) {
$scope.slides = [];
myService.loadStuff($scope, ..., function(){
console.log($scope.slides);
}, function(data, status) {
console.log('Could not retrieve stuff');
}).update();
}]);
Which can be detailed as follows:
MyServices calls $http.get behind the scenes.
An array of slides will be shown by console when there is an http success. Right now this is the case.
An error message will be shown by console when there is an http error. Right not it is NOT the case.
Finally, the images are attached correctly to the dom. I can be sure about this because I can inspect it in my browser. however the carousel height (and contents height) is 0.
What am I missing? How can I fix it?
I actually forgot to correctly specify the index property. If there is no index to match against, then there is no way to tell which image is active. When no image is active, the container has height 0
From uibootstrap doc:
As you can see, you need to declare the height of the carousel in the container div

Polymer 1.0 paper-card displays {{ }} binding variables as it is inside Angularjs ng-repeat - [Issue only in Chrome]

I am very new to angularjs, i have done some experimental projects in Polymer 0.5, so new to Polymer 1.0 as well.
I am facing an issue like inside ng-repeat i want to display some paper-card.
This issue is only on Chrome browser, In Firefox and IE-edge it is coming fine.
<paper-card heading="{{ team.name }}">
<div class="card-content">Some content</div>
<div class="card-actions">
<paper-button>Some action</paper-button>
</div>
</paper-card>
//--------------------------- HTML ----------
<div class="row content">
<div><h3>Teams <img ng-show="loading" ng-src='images/loader2.gif' width="30px" height="30px"/></h3></div>
<div ng-repeat="team in teams" ng-repeat="team in teams | filter:teamsFilter">
<div>
<style>
.collapse-content {
padding: 15px;
border: 1px solid #dedede;
}
</style>
<paper-card heading="{{ team.name }}">
<div class="card-content">Some content</div>
<div class="card-actions">
<paper-button>Some action</paper-button>
</div>
</paper-card>
</div>
</div>
</div>
//--------------------------- HTML -------------
I am using ng-polymer-element module,
I have the below code in my application app.js
angular.module('ng-polymer-elements').constant('$ngPolymerMappings', {
paperCard: {
ngModel: function property(element) {
return element.hasAttribute('multi') ? 'selectedValues' : 'selected';
},
ngHeading: '=heading'
}
});
window.addEventListener('WebComponentsReady ', function() {
angular.bootstrap(wrap(document), ['myApp']);
});
The Card header is coming fine but the binding variable is also displaying inside the card.
I inspect the HTML in the browser, i could see the paper-material is added twice and the second one is showing the brackets as it is.
Any help is highly appreciated. Thanks.
Most likely that Angular is not loaded properly; therefore, it hasn't kicked in to evaluate the expressions in the braces. Please post your entire HTML page.

add svg element at runtime in angular with 2 way data binding

I want to add svg element line at runtime with ng-attr-x1={{some scope varaible}}.
I tried 2 ways:
In 1 way I tried with $compile:
var g=angular.element(document.createElementNS("http://www.w3.org/2000/svg", "g"));
var line=$compile('<line ng-attr-x1={{$scope.array[array.length-1].x1}} ng-attr-y1={{$scope.array[array.length-1].y1}} ng-attr-x1={{$scope.array[array.length-1].x2}} ng-attr-x1={{$scope.array[array.length-1].y2}} style="with mandatory styling for line">')($scope);
g.append(line);
parentg.append(g);
In this method line is not showing and g is showing with 0px height and width.
In a 2 way I treid like :
var line=angular.element(document.createElementNS("http://www.w3.org/2000/svg", "line"));
line.attr('ng-attr-x1','scopeVariable');
line.attr('ng-attr-x2','scopeVariable');
line.attr('ng-attr-y1','scopeVariable');
line.attr('ng-attr-Y2','scopeVariable');
In this ng-attr attributes does not resolved to x and y. In DOM it shows as
This is possibly coming in way too late to help you, but I was stuck for a little while on the same question.
Turns out that $compile can take an element created with document.createElementNS() - like this:
var actApp = angular.module('actApp', []);
actApp.controller('shapeController', ['$scope', '$compile',
function shapeController($scope, $compile) {
$scope.color = 'green';
var svgEle = $(document.getElementById('mySvgElement'));
var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
line.setAttribute('x1', '0');
line.setAttribute('x2', '0');
line.setAttribute('x2', '20');
line.setAttribute('y2', '20');
line.setAttribute('style', 'stroke: {{color}};');
svgEle.append($compile(line)($scope));
}
]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="actApp">
<div ng-controller="shapeController">
<input type="button" ng-click="color='blue'" value="To blue" />
<br />
<svg id="mySvgElement" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
</svg>
</div>
</div>
Hope this saves someone a little bit of time in the future.

AngularJs - Error while using index of ng-repeat in map element

I'm trying to launch an ng-click function inside an ng-repeat but I get a problem, while clicking the element, the function always pick the last occurrence of my loop.
To be more precise here's an example:
<div ng-controller="qualityController">
<div ng-repeat="quality in qualities">
<img src ={{ asset('bundles/mybundle/img/jauge_normal.png') }} width="160" height="160" alt="Circle" usemap="#circle">
<div class="g-performance-rate-knob">
<input type="text" data-angleOffset=180 data-angleArc=360 data-fgColor="#ff7200" data-width="116" data-height="116" data-step="0.1" data-min="0" data-max="100" data-readOnly=true knob class="dial" ng-model="quality.note">
</div>
<map name="circle" id="circle" ng-click="loadQualityDetail(quality.id)">
<area shape="circle" coords="80,80,80" data-toggle="modal" data-target="#modal-stars-{[{ quality.id }]}" class="more" alt=""/>
</map>
</div>
</div>
Js:
app.controller('qualityController', function ($scope,$http)
{
qualities = [];
qualities.push({id : 1});
qualities.push({id : 2});
qualities.push({id : 3});
qualities.push({id : 4});
$scope.loadQualityDetail = function(qualityId)
{
console.log(qualityId);
}
});
Wherever I click, I get "4" in my console.
Note: I use jQuery Knob library. But it seems like the problem appear on map or area elements.
If you need more information please tell me I could make a fiddle.
Thanks by advance,

Resources