我正在尝试将范围注入angular-translate指令。但它显示
angular.min.js:6 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=navBar&p1=Error%3A%…eb%20(http%3A%2F%2Flocalhost%3A8080%2Fsrc%2Fjs%2Fangular.min.js%3A41%3A249)
遇到上述错误。我想将控制器中的$scope
值用作$translateProvider.preferredLanguage($scope.selectedLang);
app.config(function ($translateProvider, $scope){
$translateProvider.useSanitizeValueStrategy(null);
$translateProvider.translations('english', {
'data': 'I am Ram'
});
$translateProvider.translations('telugu', {
'data': ' \u0C28\u0C47\u0C28\u0C41 \u0C30\u0C3E\u0C2E\u0C4D'
});
$translateProvider.preferredLanguage($scope.selectedLang);
});
app.controller('langTranslate', function ($scope){
$scope.totalLang = ['english', 'telugu'];
$scope.lang = 'english';
$scope.selectedLang = 'english';
$scope.$watch(function(){
$scope.selectedLang = $scope.lang;
});
});
如果我删除$scope
和$translateProvider.preferredLanguage($scope.selectedLang);
from app.config
,则可以正常使用。但我必须在那里使用$scope
值。请帮我解决这个问题。
答案 0 :(得分:0)
也许这个问题可以帮助你理解你需要做什么
How to inject a service into app.config in AngularJS
而不是app.config($ translateProvider,$ scope)
尝试app.run($ translateProvider,$ rootScope)
app.run(function ($translateProvider, $rootScope){
$translateProvider.useSanitizeValueStrategy(null);
$translateProvider.translations('english', {
'data': 'I am Ram'
});
$translateProvider.translations('telugu', {
'data': ' \u0C28\u0C47\u0C28\u0C41 \u0C30\u0C3E\u0C2E\u0C4D'
});
$translateProvider.preferredLanguage($rootScope.selectedLang);
});
app.controller('langTranslate', function ($scope, $rootScope){
$scope.totalLang = ['english', 'telugu'];
$scope.lang = 'english';
$rootScope.selectedLang = 'english';
$scope.$watch(function(){
$rootScope.selectedLang = $scope.lang;
});
});
答案 1 :(得分:0)
请在此处找到配置文档:https://docs.angularjs.org/guide/module
在配置块内部,您只能注入提供商。
为了使用它,您可以使用@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "activity_info")
@Where(clause = "is_del = 0")
public class ActivityInfoEntity{
@Id
@GeneratedValue
private Long id;
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Fetch(FetchMode.SUBSELECT)
@OneToMany(mappedBy = "activity", cascade = CascadeType.ALL, orphanRemoval = true)
List<UserInfoEntity> users;
}
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "user_info")
@Where(clause = "is_del = 0")
public class UserInfoEntity{
@Id
@GeneratedValue
private Long id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "activity_id", nullable = false, updatable = false)
private ActivityInfoEntity activity;
}
提供程序,因为$rootScope
是模块。
希望它可以帮到你!
干杯!
答案 2 :(得分:0)
在配置阶段您无法提出要求 - 您只能询问提供商。有关更多信息,请阅读此guide
$scope