Angular bind not displaying - angularjs

Bit of a crazy one, certainly a very very frustrating one!
I have a pretty basic ng-repeat going on and it's working in 95% of the cases. However a few of the binds just aren't displaying.
Basic use:
<p>{{result.thingy}}</p>
Nothing shows up in the HTML
However if I use
<p>{{result.thingy | json}}</p>
Then it displays, but with quotemarks around it.
So the data is there, how come it won't show? Is it somehow an invalid type?
I have ported this across from another Angular app which displays it fine, so I suppose there might be a difference in the Angular version or something like that, but this seems crazy to me.
It also shows if I use | number
Apologies, I can't share the data apart from that when I print the full JSON to the screen, it looks like:
"thingy": { "pounds": "174", "pence": "08" }

Related

paging with angular-repeat (angular 1.2)

ok - so I'm using angular 1.2 to produce something like a report. It works great, except I want to simulate pages, and that's where it's breaking down. Imagine I have this:
<page>
<h1>once of section headings</h1>
<div ng-repeat="outer in outer_collection">
<h2>complicated outer collection headers</h2>
<div ng-repeat="inner in outer.stuff">
... block of information ...
</div>
</div>
</page>
so that works great - and provides one long stream of information blocks. However - now I want to say something like - create a new page every 6 blocks. This doesn't work at all. I tried making a counter and returning something like using $sce.trustAsHtml - but of course since angular is actually sticking it in the inner html - the are all being immediately thrown away.
Any ideas would be appreciated. One big thing is I don't want the headers repeated on subsequent pages. I've found a way to do it by preprocessing the data into pages, but that means I'm effectively duplicating the angular work in my controller - I'm hoping for a better way?

angularjs compare bound value after navigation

I encounter a problem that I can't resolve with the angularjs online help.
I'm writing angularjs/karma scenario test where I want to verify that a part a view which displays a purse amount persists after page navigation. The purse amount comes from a bound value.
View code:
<div class="label">Mon Compte<br>{{ User.getBalance() | currency }}</div>
Scenario code:
var b1 = binding('User.getBalance() | currency');
browser().navigateTo('/another-route');
var b2 = binding('User.getBalance() | currency');
expect(b1).toEqual(b2);
Failed scenario result:
expected {"name":"select binding 'User.getBalance() | currency'","fulfilled":true,"value":"4 353,90 €"} but was "4 353,90 €"
What I understand is that it tries to compare a promise with text value which doesn't work, but I have no idea to solve this.
The answer depends on what you are actually trying to test. Are you trying to assert that the text displayed in your VIEW is some value or are you trying to assert that the MODEL is staying the same? If it's the VIEW you are interested in you are on the right track. My suggestion would be to use Protractor rather than Karma.
Take a look at the documentation and let me know if you still can't get your tests working.
On the other hand if it is the MODEL you are interested in, things become a bit more complicated. You will not be able to simulate the browser navigation with a standard unit test. You would have to either create a mock service that lets you simulate the route provider or use a third party library like ngMidwayTester. Take a look here for more help with that.

Implementing basic next/previous picture

I'm trying to convert the Adjuster example mentioned here: http://agiletoolkit.org/learn/understand/view/interactive
into a View that is able to show me the next/previous picture of a list of given images.
I guess the number in the example could be an index into an array of pictures.
I'm just not sure how to provide the list of pictures, when all the code is put in init() for the View, so no way to give it the picturelist before that...
Should I use memorize/recall for this list also to prevent it getting lost upon reload ?
is there another example that might help me?
I think you what you are doing can be much easier done with a classic JavaScript Lightbox script. You would supply it list of images and it would show one full-screen.
If not, you can use this:
https://gist.github.com/romaninsh/7217119
This will give you slides similar to the ones on http://agiletech.ie/
Be advised that this code is a little old.

getting value in angularjs and quotemark

I have some project written by someone else using AngularJS and i have to do small changes in it.
There are forms, where user can insert their own text, and it is then displayed on page.
But as far, as i can see, it's not save.
For example, here is fragment of TPL displaying images:
<img src="{$category->iconUrl}" alt="{$category->name}" title="{$category->name}">
Everything works fine, until user will input quote mark in category name.
is there any way to add something like php "addslashes"? in easy way?
So far we've spend with 3 coworkers 6 hours each on so simple task and we all already hate AngularJS :) But work must be done.
It lookes like the category name is inserted in PHP rather than by AngularJS.
If it is Smarty, then the correct syntax would be:
<img src="{$category->iconUrl}" alt="{$category->name}"
title="{$category->name|escape}">

How to add a custom field into template.php using Zen sub theme

First time poster here, I'm a designer not skilled at all with php and I have a small issue I don't seem to be able to solve. I'm making a site in drupal 7 using a sub theme on zen.
Btw this is a great CMS, even though people say it's really more a developers CMS. I have no trouble to do what I need using views, rules, display suite etc. So a big thank you for all the developers out there making this such a good CMS. But for this apparently simple problem... no module will help me (I think) and I'm kinda stuck.
So here it is: I'd like to add a subtitle next to the title in all my pages.
So what I did was to add a custom field into the content type basic page (machine name: field_sub_title) which is a simple text field.
I uncommented the following line in my template.php
function mytheme_preprocess_page(&$variables, $hook) {
$variables['sub_title'] = t('field_sub_title');
}
Now my question is how do I load the content of my custom field into that variable?
I know i need to change the second part, but I don't have a clue as into what I need to change this.
Displaying the variable into the the page.tpl.php is something I know about so I only need help with the first part.
{EDIT}
Ok I found how to do this :)
I was looking for a solution in the wrong place. I don't need to change any thing in the template.php file.
Just needed to add this bit of code into my page.tpl.php:
<?php
print $node->field_sub_title['und'][0]['value'];
?>
So I'm posting this here for other Drupal newbies struggling with this....
Your solution may work for now, but there may be a more Drupal-y way to handle a problem like this. If you haven't noticed any problems yet, you may find one or more of the following issues down the road:
Someone who doesn't know php or Drupal theming may need to change the way this works.
If you're like me, you may forget where exactly in code this was implemented.
You may see superfluous markup and/or errors on nodes (content) that do not have this sub-title field (ie. event content not having a sub-title field while basic pages and news articles do).
When you add a field to a content type, it will automatically appear anytime content in that content type is displayed. You should be able to add the sub-title field for your page, event or whatever else you need and have it automatically appear in the markup.
You can 'manage display' of a content type to drag and drop the order for fields to appear. You could take it a step further by using a module like Display Suite to add formatting or layout per-content type.
If you feel like this isn't good enough and the markup for the subtitle must be at the same level as the page title (which is rare), at least add an if statement to make your code check to see if the variable is present before trying to print it. I'd also add a new variable and comments for code readability.
<?php
$subtitle = $node->field_sub_title['und'][0]['value'];
if($subtitle){
print $subtitle;
}
?>
Consider using field_get_items or field_view_value, or at least use the LANGUAGE_NONE constant instead of 'und'
See https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 and https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7
This has the added benefit of reducing the number of potential security holes you create.

Resources