我有这个配置:
var myApp = angular.module('myApp', []);
myApp.factory('Data', function () {
return { message: "I'm data from a service" };
});
function FirstCtrl($scope, Data) {
$scope.data = Data;
}
function SecondCtrl($scope, Data) {
$scope.data = Data;
}
使用硬编码的Data.message,一切正常,但是如何通过模板将值传递给Data.message?我想避免使用额外的http请求。
答案 0 :(得分:0)
尝试按如下方式设置属性。
ng-init="data.message='My message from template'"