0

How do I insert dynamically items from this array to the filter that is in wizard.html page , for when the templateUrl , which is on the route , make the call can be rendered in wizard.html page.

Controller

angular.module('tareasApp')
  .controller('NatureCtrl', function ($scope, $routeParams) {

    $scope.pageName = $routeParams.pageName;

    $scope.items =[
     {    
          href:'/sound-waves', 
          img:'waves.jpg', 
          video:'//www.youtube.com/watch?v=OG2eGVt6v2o',
          description:'Those Relaxing Sounds of Waves'
     },
     {    
          href:'/nature-relaxing-sound', 
          img:'ocean.jpg', 
          video:'//www.youtube.com/watch?v=SWR0GdC7_40',
          description:'Nature Sounds Relaxing Ocean Sounds'
     }
    ];  
 });

Page wizard.html

<div ng-controller="NatureCtrl">
 <div ng-repeat="item in items | filterBy: ['href']: ''Insert here , dynamically , the items of  array correspondent the accessed page" >

    <img ng-src="images/{{ item.img }}" width="400" height="200" >

    <p>{{item.description}}</p>

    <iframe width="655" height="400" ng-src="{{ item.video }}" frameborder="0" allowfullscreen></iframe>   
</div>
</div>

Route

angular.module('tareasApp')
  .config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider

.when("/:pageName", {
     templateUrl: "views/wizard.html",
     controller: "NatureCtrl"
     })
      .otherwise({
        redirectTo: '/'
      });    
  });

The goal is to avoid having multiple pages with the same structure.

I use the angular-filter for simpler tasks , the hardest do not know how to configure. If you have any other way to do also serves the important thing is to solve this problem.

3
  • I dont think you need filter or this! Commented Feb 26, 2015 at 11:31
  • Which otherwise would have so I can solve this problem ? Commented Feb 26, 2015 at 11:44
  • After a few days doing tests I managed to fix the filter as wanted: <div ng-repeat="item in grupo = (grupo|filterBy: ['href']:pageName).slice(0, 1)"> Commented Mar 4, 2015 at 3:35

2 Answers 2

1

Pick the right item in the controller instead of doing so in the template.

$scope.item = $scope.items.filter(function(item) {
  return item.href.indexOf($routeParams.pageName) === 1;
})[0];

And remove the div with ng-repeat.

Sign up to request clarification or add additional context in comments.

6 Comments

Wow! You are smart ! Worked very well. Now I'll do some tests and then return ...
The first controller operates normally , those below are being influenced and do not work . Do you know any way to solve this?
What do you mean by 'do not work'? Nothing is shown or the first page is kept shown? And what are the exact page names that you use?
In folder controllers I have 5 files js: humor.js, main.js, promissor.js, quadrinhos.js end terra.js, the pages that are under the control of humor.js are functioning normally, both principal and articles. The main pages that are up area of ​​other controllers appear the page wizard.html, however, should appear pages main.html, promissor.html, quadrinhos.html end terra.html, articles on these pages are functioning normally.
Sorry, I don't understand what you mean.
|
0

After a few days doing tests I managed to fix the filter as wanted.

The angular-filter facilitates the use of filters. Then I used the filterBy: ['href']: and added the pageName, which is the file name used na $routeParams.

<div ng-controller="NatureCtrl">
 <div ng-repeat="item in grupo = (grupo|filterBy: ['href']:pageName).slice(0, 1)">

    <img ng-src="images/{{ item.img }}" width="400" height="200" >

    <p>{{item.description}}</p>

    <iframe width="655" height="400" ng-src="{{ item.video }}" frameborder="0" allowfullscreen></iframe>   
</div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.