【发布时间】:2015-10-31 00:25:13
【问题描述】:
我正在使用角度 1.3
Plunker 代码在这里http://plnkr.co/edit/J7TSfUcNID11BZBEaBBr?p=preview
在我的代码中,我有 ngRoute,它为索引页面定义了一个控制器,它实现了如下的提取。
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: '/assets/app/html/home.partial.html',
controller: function($scope) {
$scope.fetch = function(purchase) {
console.log("fetch is called, load data and show the grid");
$scope.grid = {};
$scope.grid.isActive = true;
//how to refresh purchases directive from here
//it should also pass the from and to dates
//based on that purchases will fetch the backend data
}
}
})
}]);
我有一个指令 Purchases,我试图重新加载它,包括通过资源获取数据。当日期更改时,我想再次从后端查询数据并在 Purchases 指令内的网格上刷新它。
我使用 ngResource 插件,所以从后端获取数据是有序的。 加载页面时,链接功能只运行一次。
将 from 和 to 日期传递给指令的最佳方法是什么(检查 plunker index.html)?
当日期更改时,我没有看到指令(链接功能)将其拾起。我尝试了 html id、name 和 model,但它们都不起作用。
【问题讨论】:
-
您如何将日期传递到指令中?您是否使用隔离范围?您是否尝试过使用
scope.$watch?
标签: angularjs angularjs-directive