我正在寻找一种在angularjs函数中使用全局变量的方法。
我发现这种方式,将全局变量用作角度var:
var AppSettings = angular.module('settingsApp', []);
AppSettings.controller('settingsCtrl', ['$scope', '$window', function($scope, $window) {
$scope.sessionUID = $window.sessionUID;
/** function to update user details after edit from list of user php **/
$scope.changefunction = function() {
alert("perfect");
};
}]);
var MyApp = angular.module('biqs_settings_app', ['settingsApp']);
但现在我无法运行“改变功能”。
错误:
TypeError: Cannot read property '0' of null
at $parseFunctionCall (angular.js:12346)
at callback (angular.js:21435)
at Scope.$eval (angular.js:14401)
at Scope.$apply (angular.js:14500)
at HTMLButtonElement.<anonymous> (angular.js:21440)
at HTMLButtonElement.eventHandler (angular.js:3014)
我做错了什么?
答案 0 :(得分:0)
如果您在HTML中正确使用settingsCtrl
控制器,那么一切都会有效:
<div ng-app="biqs_settings_app" ng-controller="settingsCtrl">
<button ng-click="changefunction()">Test</button>
</div>