角度扩展控制器

时间:2014-11-03 09:14:21

标签: javascript html angularjs

我的角度有两个控制器 - 'table'和'studentTable'。

问题是'table'中的$ scope无法读取'studentTable'中$ scope的数据。

 Suppose $scope.data2 will be equal to $scope.data by clicking the button but it does not work. 

我有两个控制器的原因是我有很多表,比如'teacherTable','classRoomTable'等,它们都使用'table'的功能。这有点像扩展'表'。有什么方法可以使它有效甚至更好吗?

(function () {
"use strict";
angular.module("app", []).controller("table", ['$scope', function ($scope) {
        return $scope.displayData = function () {
            return $scope.data2=$scope.data;
        };
    }])
    .controller("studentTable", ['$scope', '$http', function ($scope, $http) {
        return $scope.getData = function () {
            $http.post('/api/getUserByUserId/1', {}).success(function (data, status, headers, config) {
                return $scope.data = data;
            }).error(function (data, status, headers, config) {
            });
        }, $scope.getData();


    }])
})
<div data-ng-app="app">
<div data-ng-controller="table">
<div data-ng-controller="studentTable">
    {{data}}
    {{data2}}
    <button ng-click="displayData()">click</button>
</div>

0 个答案:

没有答案
相关问题