I'm getting a very very strange issue with Angularjs, I'm using a directive where I defined an inline template on page like this:
<script type="text/ng-template" id="breadcrumb.html"> {[ state.current.displayName ]} </script>
However, I'm getting this weird error:
> Error: JSON.parse: expected property name or '}'
> fromJson#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:1035
> #http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:6926
> transformData/<#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:6901
> forEach#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:302
> transformData#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:6900
> transformResponse#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:7570
> qFactory/defer/deferred.promise.then/wrappedCallback#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:10905
> qFactory/ref/<.then/<#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:10991
> Scope.prototype.$eval#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:11906
> Scope.prototype.$digest#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:11734
> Scope.prototype.$apply#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:12012
> bootstrap/doBootstrap/<#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:1299
> invoke#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:3697
> bootstrap/doBootstrap#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:1298
> bootstrap#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:1311
> angularInit#http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:1260
> #http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js:20534
> x.Callbacks/c#http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js:4
> x.Callbacks/p.fireWith#http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js:4
> .ready#http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js:4
> q#http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js:4
Now, if I actually add something into the template, for example any random character like this:
<script type="text/ng-template" id="breadcrumb.html"> a{[ state.current.displayName ]} </script>
Then the error goes away, everything renders fine.
PS: Note that I changed from {{}} to {[]} to avoid syntax conflict with Twig
Edit:
In respond to the interpolate issue, I already use:
angular.module('myapp', []).config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[').endSymbol(']}');
}
);
Shouldn't this be enough. And if that doesn't work, the why does putting a random character 'a' to it helps?
Edit 2:
Plunker added:
Please check this link for working code:
http://plnkr.co/edit/OQiJovrNzOraJdsSXeSY?p=preview
Please check this link for non-working code:
http://plnkr.co/edit/IzGpTdnqmO5MxtldnKec?p=preview
Angular expects {{}} for interpolation.
To avoid conflicts you can use ng-bind:
<script type="text/ng-template" id="breadcrumb.html" ng-bind="state.current.displayName"></script>
But, I've never tried it with a <script> tag though.
This is a confirmed issue of the current version of Angular JS (1.2.x)
I have submitted a ticket here:
https://github.com/angular/angular.js/issues/5756
Related
My application requires to test favorite feature for any product.Products List & UI
When a user click on the heart icon shown in the snippet, it will add that product into Favorites list. I would like to know about the Capybara/Cucumber method to click on the heart icon.
I have tried using XPATH but it seems not working. The code that I tried is as follow.
When(/^I click on the favourite icon on the first product$/) do
find(:xpath,'/html/body/div[1]/div[2]/div/div/div/span/div/div/div/div[3]/div[1]/span[1]/div/div/div/div/div[4]/div[2]/div/favorite/a').click
end
I have also tried following capybara method using XPATH. It is also not working.
When(/^I click on the favourite icon on the first product$/) do
find(:xpath,'//a[contains(., "#heart")]).click
end
Also, I tried following code which is throwing out an error.
When(/^I click on the favourite icon on the first product$/) do
within("div.search-results-wrapper") do
find(first('a.ng-scope')).trigger(:mouseover)
end
end
Error:
The given selector #<Capybara::Node::Element:0x007fd18d841690> is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified (Selenium::WebDriver::Error::InvalidSelectorError)
The HTML code for the Favorite icon is as follow:
<favorite product="result" ng-if="!ui.showIpsaProductCell()" class="product-action ng-scope ng-isolate-scope"><a ng-mousedown="product.favoriting = true" ng-mouseenter="product.showList = true" active="::product.favoriting" ng-click="toggle(true)" class="ng-scope active">
<i ng-class="::{
'icon-heart-filled':
product.hasFavorite || !showCount || newProductPage,
'icon-heart-outline':
!product.hasFavorite && showCount && !newProductPage
}" class="heart icon-heart-filled"></i>
<!-- ngIf: ::showCount --><span class="count ng-scope" ng-if="::showCount">
1
</span><!-- end ngIf: ::showCount -->
<!-- ngIf: ::addToList && product.hasFavorite --><div component="add-to-list" ng-if="::addToList && product.hasFavorite" class="ng-scope">
<!-- ngInclude: '/modules/components/add-to-list/add-to-list.tpl.html' --><span ng-include="'/modules/components/add-to-list/add-to-list.tpl.html'" ng-controller="AddToListCtrl" class="ng-scope"><div ng-mouseleave="product.showList = false" class="add-to-list-desktop ng-scope">
<!-- ngIf: product.showList -->
<!-- ngIf: product.showListMenu && product.showList -->
</div>
</span></div><!-- end ngIf: ::addToList && product.hasFavorite -->
</a></favorite>
Since you have multiple "favourite" icons you would need to find your icon within a given parent container, not being able to see the full html page it would go something like:
within(".myParentContainer") do
find(".icon-heart-filled").click
end
All is in the title. I want to use the CrytoJS lib in an AngularJS application and I can't get rid of this.
I install crytoJS with bower:
bower install cryptojslib
Then I load the lib I need :
<script type="text/javascript" src="/public/system/lib/cryptojslib/rollups/md5.js"></script>
<script type="text/javascript" src="/public/system/lib/cryptojslib/components/enc-base64-min.js"></script>
And I try to use the CryptoJS like that :
var pwd = CryptoJS.MD5(params.email+'|'+params.password).toString(CryptoJS.enc.Base64);
When I run this code, I've got the following error :
'CryptoJS is not defined'
I've read that it should be possible to wrap the CryptoJS into a module but I don't know how to do.
Any help would be greatly appreciated.
JM.
Shouldn't be any problems with AngularJS and CryptoJS. I setup a quick Plunker that has a hash created in a controller. No errors...
http://plnkr.co/edit/kzrr3EdHNXELVof6DVSp?p=preview
In the controller:
$scope.hash = CryptoJS.MD5("Message");
In the HTML:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
Is this different than what you are trying?
include the jsfile from rollups folder.
Even I was also getting the same error 'CryptoJS is not defined'. After this change, CryptoJS object was available
var hashObj = CryptoJS.SHA512(myString);
var hashString = hash.toString(CryptoJS.enc.HEX);
I just added those srcipt to my web page and has en error.
<script type="text/javascript" src="https://code.angularjs.org/1.3.0-rc.1/angular.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.3.0-rc.1/angular-route.js"></script>
This is exact my example and it works on Fiddle.
http://jsfiddle.net/frbrn32d/2/
junk after document element main.html:6
DOMException [NS_ERROR_DOM_BAD_URI: "Access to restricted URI denied"
code: 1012
nsresult: 0x805303f4
location: https://code.angularjs.org/1.3.0-rc.1/angular.js:9032]
Check out your fiddle. I made a change and it seems to be working.
You had a typo there. It should be alert not alerT.
http://jsfiddle.net/1mjgf4u8/3/
I am using an ng-switch in angularjs to have dynamic content in my page, dependent on the url. And I am managing my project with yeoman. Here is the code of the dynamic content generation:
html:
<div class="div-content bgcontent" id="content">
<span ng-switch on="renderPath[0]">
<div ng-switch-when="home" ng-include="'partials/home.html'"></div>
<div ng-switch-when="gallery" ng-include="'partials/gallery.html'"></div>
</span>
</div>
controller:
$scope.renderPath = $location.path().split('/');
// remove first entry because it's empty string
$scope.renderPath.shift();
This works perfectly well when running the stuff with 'yeoman server'. But if I build with 'yeoman build:minify', it doesn't work anymore afterwards. It hits an assertion:
at assertArg (http://host:8888/scripts/vendor/d10639ae.angular.js:973:11)
at Object.ngDirective.compile (http://host:8888/scripts/vendor/d10639ae.angular.js:13474:5)
at applyDirectivesToNode (http://host:8888/scripts/vendor/d10639ae.angular.js:4047:32)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3794:14)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3799:14)
at compile (http://host:8888/scripts/vendor/d10639ae.angular.js:3739:29)
at update (http://host:8888/scripts/vendor/d10639ae.angular.js:13685:22)
at $get.Scope.$broadcast.next (http://host:8888/scripts/vendor/d10639ae.angular.js:8002:24)
at Array.forEach (native)
at forEach (http://host:8888/scripts/vendor/d10639ae.angular.js:110:11) <!-- ngSwitchWhen: home -->
Does someone know how to fix this? Or where I need to look to debug it?
If you are using dependency-injection within your scripts, make sure to use the minify-proof syntax as described here: http://docs.angularjs.org/guide/di
I have setup and installed the Composite C1 4.0 beta, along with the latest MVC Player build (from 12/7/2012 nightly), but whenever I call the MVCPlayer function, it outputs additional tags on the page. For example, I am calling a MVCPlayer function for breadcrums. This is the output:
..... before breadcrum content .....
<a name="site-nav" class="screen-reader"></a>
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
<html>
<head />
<body>
<!-- START BREADCRUM SECTION -->
<ul id="breadcrumbs">
<li>Homep</li>
<li>Events</li>
</ul>
<!-- END BREADCRUM SECTION -->
</body>
</html>
</body>
</html>
<div class="clear"></div>
</div>
..... rest of page .....
As you can see, it is in the middle of the page. The MVCPlayer is returning an XDocument in the render function. So, how do I get rid of the extra tags before the START & END BREADCRUM SECTION comments? The page renders fine, but this is impacting the ability for me to use a page filter to add additional content to the output, such as switching out image tag src's so I can use a jquery script to perform lazy loading images (see http://www.appelsiini.net/projects/lazyload).
Any thoughts?
Thanks!
Chad
The output of the actual breadcrums page is simply <ul><li>...</li></ul>, and there are no errors in the log files. The MVC Player actually adds the additional code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
</body>
</html>
In the Player.cs file, here is the code:
var sbHtml = new StringBuilder();
sbHtml
.Append(#"<html xmlns=""http://www.w3.org/1999/xhtml"">
<head/>
<body>")
.Append(responseWriter.ToString())
.Append(#"
</body>
</html>");
try
{
return XDocument.Parse(sbHtml.ToString());
}
I was able to modify the /Renderers/Page.aspx.cs and changed this line to "strip" out the extra tags:
Original:
xhtml = _renderingContext.FormatXhtml(xhtml);
Updated:
xhtml = _renderingContext.FormatXhtml(xhtml.Replace(#"<html xmlns=""http://www.w3.org/1999/xhtml"">", "").Replace("<html>", "").Replace("<head />", "").Replace("<head></head>", "").Replace("<body>", "").Replace("</body>", "").Replace("</html>", ""));
I'm sure there is a better solution than this? :)
Chad
It could be that somewhere else on the the page you have markup which makes the whole result document and invalid XHTML, and therefore the system cannot process it correctly.
Try to
a) Check the log files to see if there any related warnings
b) validate the output xhtml http://www.xmlvalidation.com/