Html 我正在练习括号中的角JS。使用Value Recipe时,我没有得到正确的输出

Html 我正在练习括号中的角JS。使用Value Recipe时,我没有得到正确的输出,html,angularjs,Html,Angularjs,使用value recipe时,我没有收到预期的消息 我得到的输出是{{message},但我希望“hai服务正在工作!!” 请分享我的错误 HTML代码:Injector.HTML <!DOCTYPE html> <html> <head> <title>Practicing Angular JS</title> <script src="http://ajax.googleapis.co

使用value recipe时,我没有收到预期的消息

我得到的输出是
{{message}
,但我希望
“hai服务正在工作!!”

请分享我的错误

HTML代码:Injector.HTML

<!DOCTYPE html>
<html>
    <head>
        <title>Practicing Angular JS</title>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>   
        <script src="Injector.js"></script> <!-- Injector module file name -->

    </head>


 <body ng-app="injectormodule">   <!-- root module-->


<div ng-controller="controllerInjector"> 
    {{message}} 
    <!-- controller name-->

     </div>  


    </body>

</html>
服务:(价值配方)


您需要将
服务
注入
控制器
,并需要创建相同的模块。 请参阅此示例,它使用服务方法获取文本


请参见注释中的其他fiddle链接

您必须在
injectormodule
之前定义
服务模块
,否则其创建将失败(因为无法找到
服务模块
相关性)

由于创建
injectormodule
失败,因此
ng app=“injectormodule”
也将无法在DOM上引导Angular,因此不会解释双括号(
{{message}


这是一个工作模式。

您应该将服务注入控制器,而不是模块中。好吧,这不是一种服务,而是一种价值。它是一样的,你把它注入到你想要使用它的控制器中。我像下面那样尝试过,但是我仍然得到{{message}}作为输出。angular.module(“injectormodule”,[])//服务的名称是servicemodule.controller(“controllerInjector”,[“$scope”,“message”“servicemodule”函数($scope,message,servicemodule){$scope.message=message;}]);如何将服务注入控制器?如何创建相同的模块?下面是我的代码,我做的对吗?angular.module(“injectormodule”,[“servicemodule”])//服务的名称是servicemodule.controller(“controllerInjector”,[“$scope”,“message”,function($scope,message){$scope.message=message;}]);angular.module(“injectormodule”,[“servicemodule”])//服务的名称是servicemodule.controller(“servicemodule”,[“$scope”,“message”,function($scope,message){$scope.message=message;}])@Sourabh:请参阅答案中附带的fiddle示例。我已经更改了Injector.js,如下所示,但仍然得到与{{message}相同的输出。小提琴的例子令人困惑,我不明白。angular.module(“injectormodule”,[])//服务的名称是servicemodule.controller(“controllerInjector”,[“$scope”,“message”“servicemodule”函数($scope,message,servicemodule){$scope.message=message;}])@苏拉布:如果你只想使用
.value()
,那么这里就不需要服务了。看这个。如果两个都需要,那么创建两个属性并从两个源获取数据。看到这个很抱歉迟回复,它不工作。透露一些信息。
var app = angular.module("injectormodule", ["servicemodule"])//name of service is servicemodule
    .controller("controllerInjector", ["$scope", "message", function($scope, message){
        $scope.message = message;
}]);
var myapp = angular.module("servicemodule", [])
    .value("message", "hai services are working!!");