AngularJS 自定义常量服务

<!DOCTYPE html>  
<html ng-app="App">  
<head>  
    <meta charset="UTF-8">  
    <title>AngularJS 自定义常量服务</title>  
</head>  
<body>  
    <div ng-controller="DemoController">  
        {{author}}  
        {{version}}  
    </div>  
    <script src="./libs/angular.min.js"></script>  
    <script>  
        var App = angular.module('App', []);  
  
        // 自定义常量服务  
  
        // 提供了3种方法实现自定义服务  
        // factory、service、value  
  
        App.value('author', 'geng');  
        App.value('version', '1.0');  
  
        // 本质上一个服务  
        // 从表现形式上是一个常量  
        // 常量就是不变的值与变对量相对应  
  
        // 声明依赖调用服务  
        App.controller('DemoController', ['$scope', 'author', 'version', function ($scope, author, version) {  
            $scope.author = author;  
            $scope.version =version;  
  
        }])  
  
    </script>  
</body>  
</html>

欢迎分享本文,转载请保留出处:前端ABC » AngularJS 自定义常量服务

分享到:更多 ()

发表评论 0