javascript - Resolve in directives AngularJS -
how can use resolve in config in directives? have such code:
angular.module('config', ['ngroute', 'resources.params']) .config(['$routeprovider', function($routeprovider) { 'use strict'; $routeprovider .when('/config',{ templateurl: 'templates/config/config.tpl.html', controller: 'configctrl', resolve: { params: ['params', '$route', function(params, $route) { if ($route.current.params.skey) return params.get($route.current.params.skey); else return null; } ] }, reloadonsearch: true }); } ]) .controller('configctrl', ['$scope','$route','$routeparams', 'params','params', function($scope,$route,$routeparams,params,params){ 'use strict';
i can use "params" in controller because wrote "params: [..." in .config want use "params" in directive:
.directive('mapsysitem', ['$location', '$routeparams', '$freshmark', function($location, $routeparams, $freshmark) { 'use strict'; return { restrict: 'e', require: '^mapsyslist', scope: { zoomlist: '@', item: '=', skey: '=', select: '&' }, replace: true, templateurl: 'templates/map/mapsysitem.tpl.html', controller: ['$element', '$scope', 'system','$filter','params', function($element, $scope, system, $filter, params) { ..... }] }; }]);
if add "params" controller options have "unknown provider: paramsprovider <- params". how can solve problem? thaks you.
due use of isolated scope within directive, need pass parameter attribute in directive node
set scope in app controller
.controller('configctrl', ['$scope','$route','$routeparams','params','params', function($scope,$route,$routeparams,params,params){ $scope.myparams=params
then pass $scope.myparams directive
<mapsysitem param='myparams'></mapsysitem>
then create 2 way binding in scope
scope: { param:'=' },
then able use in directive controller
controller: ['$element', '$scope', 'system','$filter', function($element, $scope, system, $filter ) { var myparams= scope.param
Comments
Post a Comment