2015-04-07 145 views
0

这是一个教育帖子。 我想了解为什么我的plunker这里不起作用。我只是想将facotry连接到控制器,然后使用ng-repeat导入数据。控制器和工厂AngularJS

我已经尝试了几种语法,但无法编写正确的实现。 Tahnks为您提供帮助。

控制器:

var wmapp = angular.module('wmapp' []); 

    .controller('restaurantlistController', function ($scope, $rootScope, restaurantsFactory) { 
    "use strict"; 
    $scope.restaurantList = restaurantsFactory.getRestaurants(); //call to restaurantfactory 
}) 

工厂:

angular.module('wmapp.factory_restaurants', []) 

.factory('restaurantsFactory', function() { 
    "use strict"; 
    var factory = { 
      Restaurants : [ 
       {Name: 'A La Biche Au Bois', venueType: 'Restaurant ', subCuisine: 'Italian', subsubCuisine: 'Classic/traditional', address: '45 Avenue Ledru-Rollin', cp: '75012', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST002', phoneNumber: '+331 43 43 34 38', website: '', lat: 48.8482040, long: 2.3706140, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'}, 
       {Name: 'Allard   ', venueType: 'Restaurant ', subCuisine: 'French', subsubCuisine: 'Classic/traditional', address: '41, rue Saint-André des Arts', cp: '75006', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST004', phoneNumber: '+33158002342', website: 'http://www.restaurant-allard.fr/en', lat: 48.8532490, long: 2.3409810, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'}, 
       {Name: 'Ambassade d\'Auvergne', venueType: 'Restaurant ', subCuisine: 'French', subsubCuisine: 'Auvergne region', address: '22 Rue du Grenier Saint-Lazare', cp: '75003', city: 'Paris', country: 'France', countryCode: 'FR', itemid: 'PARIREST005', phoneNumber: '+331 42 72 31 22', website: 'http://www.ambassade-auvergne.com/', lat: 48.8631310, long: 2.3534140, icon: 'img/restaurant_pointer_WMcustom_40x49_v3.png'} 

    // more restaurans 



      ], 
      getRestaurants : function() { 
       return factory.Restaurants; 
      }, 
     }; 
    return factory; 

}); 

HTML:

<div data-ng-controller="restaurantlistController" ng-repeat="restaurant in restaurantList " href="#"> 
    <article class="item_frame"> 
     <div class="marker_left_container"> 
     <img class="venue_rest_marker" ng-src="{{restaurant.icon}}" /> 
     <span class="venu_type_text">{{restaurant.venueType}}</span> 
     <span class="distance_from_user_rest">0.7 km</span> 
     <span class="distance_from_user_rest2">from current location</span> 
     </div> 
     <div class="restaurant_details_container"> 
     <h1 class="restaurant_name_inlist">{{restaurant.Name}}</h1> 
     <span class="restaurant_detail_inlist2">{{restaurant.subCuisine}}       <br /> 

     {{restaurant.subsubCuisine}}</span> 
     <span class="restaurant_address">{{restaurant.address}},        <br /> 
     </span> 
     <span class="restaurant_address">{{restaurant.cp}}, {{restaurant.city}}        <br /> 
      <br /> 
     </span> 
     <span class="restaurant_others">{{restaurant.phoneNumber}}       <br /> 
     </span> 
     <span class="restaurant_others">{{restaurant.website}}       <br /> 
      <br /> 
     </span> 
     </div> 
    </article> 
    <!--main article frame 1 --> 
    </div> 

回答

0

有更多然后4个误差主要semicolon , dots , module不包括错误 检查这个环节,现在正在为指出这些错误plunker

+0

感谢 – lauWM