【发布时间】:2014-09-08 02:46:12
【问题描述】:
HTML:
<html ng-app="san">
<head>
</head>
<body ng-controller="sanctrl">
<div>
AngularJS</div>
<div ng-view="">
</div>
<button type="button" ng-click="init()" class="btn btn-blue">
Save</button>
</body>
</html>
主控制器:
san.controller('sanctrl', function ($scope, $http, $q, $location, $anchorScroll, $filter, dataFactory) {
//nothing in this controller.
});
ng-view 控制器:
san.app.controller('cereals', function ($scope, dataFactory) {
$scope.init(){
$scope.test = "test";
};
});
我正在尝试从 ng-view 范围之外调用 init 方法。可能吗?如果没有,那么我们有哪些选择?
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope angularjs-service angularjs-routing