一个例子,定义了两个变量,并且把变量显示出来:
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title>interval</title> <script type="text/javascript" src="js/angular/angular.min.js" charset="utf-8"></script> </head> <body ng-controller="ctrl"> <div>{{text1}}</div> <div>{{text2}}</div> <script> var app = angular.module('myApp',[]); app.value("obj1", "aaa"); app.value("obj2",{a1:1,a2:'abc'}); app.controller("ctrl",["$scope","obj1","obj2",function($scope,obj1,obj2){ $scope.text1 = obj1; $scope.text2 = obj2.a1 + ":" + obj2.a2; }]); </script> </body> </html>