javascript - Angular extending controllers -
javascript - Angular extending controllers -
i have 2 controllers in angular - 'table' , 'studenttable'.
the problem $scope in 'table' cannot read info $scope in 'studenttable'.
suppose $scope.data2 equal $scope.data clicking button not work.
the reason why have 2 controllers have many tables, 'teachertable', 'classroomtable',etc , utilize functions of 'table'. kind of extending 'table'. there way can create works or better?
(function () { "use strict"; angular.module("app", []).controller("table", ['$scope', function ($scope) { homecoming $scope.displaydata = function () { homecoming $scope.data2=$scope.data; }; }]) .controller("studenttable", ['$scope', '$http', function ($scope, $http) { homecoming $scope.getdata = function () { $http.post('/api/getuserbyuserid/1', {}).success(function (data, status, headers, config) { homecoming $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>
javascript html angularjs
Comments
Post a Comment