您好,我正在观看几个angular.js视频,并看到value()方法用于设置一种模块范围的常量.例如,可以像这样设置Angular-UI库的配置:(coffeescript)
angular.module('app',[])
.value "ui.config",
tinymce:
theme: 'simple'
width: '500'
height: '300'
Run Code Online (Sandbox Code Playgroud)
我的应用程序目前看起来像这样:
window.app = angular.module("app", [ 'ui'])
.config(["$routeProvider", ($routeProvider) ->
$routeProvider
.when "/users",
templateUrl: "assets/templates/users/index.html"
controller: IndexUsersCtrl
.otherwise redirectTo: "/users"
])
.value 'csrf', $('meta[name="csrf-token"]').attr('content') #<---- attention here
IndexUsersCtrl = ($scope) ->
$scope.users = gon.rabl
console.log "I want to log the csrf value here" #<---- then attention
IndexUsersCtrl.$inject = ['$scope']
Run Code Online (Sandbox Code Playgroud)
但是我似乎无法通过点击与app模块相对应的'app'变量来获得该值.
我在这里读到了ST和在angularjs的google小组上,通过服务共享公共代码btwn控制器的一种方式,这个概念也适用于此吗?
谢谢!
我正在构建使用CORS请求的应用程序.我使用的每个请求都从常量中获取主机地址
angular.module('siteApp').constant('baseUrl', {
'server':'htttp://localhost/',
})
Run Code Online (Sandbox Code Playgroud)
在每个服务我用来发送这样的请求:
angular.module('siteApp').factory('DocsSvc', function ($http, baseUrl) {
var baseurl = baseUrl.server ;
$http.get(baseurl + 'document')
Run Code Online (Sandbox Code Playgroud)
是否有可能使'htttp:// localhost /'值 - 来自config.json文件到baseUrl constant或baseUrl factory?我的意思是:我如何从ajax请求中加载一些东西,让它可以访问app模块
我试过了:
.run(['$rootScope', , function ($rootScope) {
$.ajax('config.json', {async: false})
.success(function (data) {
$rootScope.HOST = data.HOST;
});
Run Code Online (Sandbox Code Playgroud)
并尝试从baseUrl访问它:
angular.module('siteApp').factory('baseUrl',function($rootScope) {
return {
server: $rootScope.HOST
Run Code Online (Sandbox Code Playgroud)
但没有运气 - baseUrl.server未定义为函数