如何将字段变量传递给ng路由配置中的指令,或者在另一个阶段?
.when('/test',{template:"<my-directive fields=field></my-directive>"})
如何在路由阶段将指令分配给指令?
答案 0 :(得分:1)
确保在定义模块依赖项时包含您的指令:
var app = angular.module('sampleApp', [
'ngRoute',
'myDirective' // here, you need to include your directive module
]);
然后,定义您的路线:
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', { template: "This is the default Route" })
.when('/test', {
template: '<my-directive fields="field"></my-directive>',
controller: 'testController'
})
.otherwise({ redirectTo: '/' });
}]);
还有一个控制器:
app.controller('testController', ['$scope', function($scope) {
$scope.field = { your: "data here" };
}]);