สวัสดีฉันกำลังดูวิดีโอ angular.js สองรายการและเห็นว่ามีการใช้วิธี value () เพื่อกำหนดค่าคงที่ทั้งโมดูล ตัวอย่างเช่นเราสามารถตั้งค่าการกำหนดค่าของไลบรารี Angular-UI ได้ดังนี้: (coffeescript)
angular.module('app',[])
.value "ui.config",
tinymce:
theme: 'simple'
width: '500'
height: '300'
และขณะนี้แอปของฉันมีลักษณะดังนี้:
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']
แต่ฉันไม่สามารถรับค่านั้นได้โดยการแตะที่ตัวแปร "แอป" ซึ่งตรงกับโมดูลแอป
ฉันอ่านที่นี่เกี่ยวกับ ST และมากกว่าในกลุ่ม google ของ angularjs ว่าวิธีหนึ่งในการแบ่งปันรหัสควบคุม btwn ทั่วไปคือผ่านบริการแนวคิดนี้จะใช้ที่นี่ด้วยหรือไม่
ขอบคุณ!