如何将数据区的原始状态状态传达给我的范围?

时间:2013-07-18 04:20:33

标签: angularjs

我有以下内容:

    <div data-ng-controller="AdminGridContentController" >
        <ng-include src="'/Content/app/admin/partials/grid-content-base.html'"></ng-include>
        <ng-include src="'/Content/app/admin/partials/table-content.html'"></ng-include>
    </div>

我的表格包括以下内容:

<div ng-form name="page">
    {{ page.$pristine }}
    <table width="100%" cellspacing="0" class="form table" >
            <tr>
                <th>ID</th>
                <th>Title</th>

            </tr>
            <tr data-ng-repeat="row in grid.data">
                <td>{{ row.contentId }}</td>
                <td><input type="text" ng-model="row.title" /></td>
            </tr>
    </table>
</div>

我想要做的是在我的grid-content-base上放一个按钮,当桌面上的数据变脏时启用该按钮。我知道我可以使用{{page。$ pristine}}检查该数据的状态,但是如何将其传达回grid-content-base.html?

请注意,我确实尝试将所有内容放在“ng-form name = page”中,但是有问题。在grid-content-base上我有一个输入选择。一旦我做了选择,它就会使页面显示为脏。

所以我仍然只想在页面上设置全局内容。$ pristine变为true或false。

1 个答案:

答案 0 :(得分:1)

始终可以选择$rootScope.$broadcast并从表格页面发送消息。这可以在网格页面中处理。

表控制器中的这种东西

$scope.$watch('page.$pristine',function(newValue) {
    $rootScope.broadcast("formUpdated",{state:page.$pristine});
});

在网格控制器中有类似的东西

$scope.on("formUpdated",function(args) {
    //args.state would have the state.
});

注意:$rootScope必须像注入$scope

一样注入控制器