【发布时间】:2016-02-16 05:04:15
【问题描述】:
示例链接:Example
大家好,
我在基于 url 的索引文件中创建了一个全局帮助按钮,正在加载动态帮助(html 文件),它工作正常。我需要确定哪个控制器被激活,并且我需要将当前的 $scope 作为参数传递给 $scope.HelpFunction function.$scope.HelpFunction 在帮助指令中可用。在指令中,我需要从当前控制器获取当前 $scope.message。基于 $scope 我需要实现一些逻辑,任何人都可以帮助我.....
.directive("help", function($location, $window){
.directive("help", function($location, $window){
return {
restrict: "A",
template: "<button ng-click=\"HelpFunction( )\">Help</button>",
scope: true,
controller: function($scope){
$scope.HelpFunction = function( ){
//Here I need to access current $scope value
alert($scope.message)
//var url =$location.url();
//$window.open(url+ '.html', '', 'width=700,height=700');
}
},
link: function(scope){
}
}
})
.controller('HomeController', function ($scope, router, $location) {
$scope.message = "Home";
$scope.TestFunction = function(data) {
console.log("Home:" + $location.url())
};
})
.controller('MainController', function ($scope, router) {
$scope.message = "Main";
$scope.TestFunction = function(data) {
console.log("Main:" + data)
};
})
.controller('Page1Controller', function ($scope, router) {
$scope.message = "Page1";
$scope.TestFunction = function(data) {
console.log("Page2:" + data)
};
})
【问题讨论】:
-
我尝试了同样的结果。可以分享一下代码吗?
-
“激活”控制器是什么意思?
标签: javascript angularjs angularjs-directive angularjs-scope angular-ui-router