'use strict';
/* App Module */
var test2 = 'tank'; //方法1,定义全局变量
var phonecatApp = angular.module('phonecatApp', [ //定义一个ng-app
'ngRoute',
'phonecatControllers',
'tanktest'
]);
phonecatApp.value('test',{"test":"test222","test1":"test111"}); //方法2定义全局变量
phonecatApp.constant('constanttest', 'this is constanttest'); //方法3定义全局变量
phonecatApp.config(['$routeProvider', //设置路由
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html' //这里没有设置controller,可以在模块中加上ng-controller
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
when('/login', {
templateUrl: 'partials/login.html',
controller: 'loginctrl'
}).
otherwise({
redirectTo: '/login'
});
}]);
'use strict';
/* Controllers */
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope','test','constanttest',
function($scope,test,constanttest) {
$scope.test = test; //方法2,将全局变量赋值给$scope.test
$scope.constanttest = constanttest; //方法3,赋值
$scope.test2 = test2; //方法1,赋值
}]);
<div data-ng-controller="PhoneListCtrl">
{{test.test1}}
{{constanttest}}
{{test2}}
</div>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有