[英]Inject factory into controller function in angularjs
我正在嘗試編碼工廠並在控制器上使用它
.controller('View2Ctrl', ['$scope', 'Alert', function($scope, Alert) {
這在控制器內部有效,但是當我嘗試在函數內部訪問它時,它是未定義的。
$scope.test_function = function(Alert) {
Alert.some_method -> undefined.
};
$scope.test_function = function() { // remove Alert
Alert.some_method -> undefined.
};
如果將服務注入控制器,則無需注入該控制器內部的功能,請檢查此方法:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.