zoukankan      html  css  js  c++  java
  • Angular 学习笔记——$provider

    <!DOCTYPE HTML>
    <html ng-app="myApp">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="angular.min.js"></script>
    <script>
    
    var m1 = angular.module('myApp',[]);
    
    m1.provider('myRandom',function(){
        return{
            bolInt:false,
            int : function(argBol){
                if(argBol){
                    this.bolInt = true;
                }else{
                    this.bolInt = false;
                }
            },
            $get:function(){
                var This = this;
                return function(num1,num2){
                    return This.bolInt?Math.round(Math.random()*(num2 - num1)) + num1: Math.random()*(num2 - num1) + num1; 
                }
            }
        }
        
    })
    m1.config(['myRandomProvider',function(myRandomProvider){
        myRandomProvider.int(true);
    }])
    m1.controller('Aaa',['$scope','myRandom',function($scope,myRandom){
        console.log(myRandom(-3,6));
    }])
    
    </script>
    </head>
    
    <body>
    <div ng-controller="Aaa">
       
    </div>
    </body>
    </html>
  • 相关阅读:
    每日博客
    每日博客
    今日收获
    今日收获
    今日收获
    今日收获
    今日收获
    今日收获
    今日收获
    今日收获
  • 原文地址:https://www.cnblogs.com/mayufo/p/5027935.html
Copyright © 2011-2022 走看看