<!DOCTYPE html>
<html ng-app="myapp">
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<style>
body {
padding-top:30px;
}
</style>
<script src="angular.js"></script>
<script>
angular.module('myapp', [])
.factory("Data", function() {
return {
msg:"hello world"
};
})
.controller("CtrlF", function($scope, Data) {
$scope.data = Data;
})
.controller("CtrlS", function($scope, Data) {
$scope.data = Data;
});
</script>
</head>
<body>
<div class="container">
<div class="col-sm-8 col-sm-offset-2">
<div ng-controller="CtrlF">
<input type="text" ng-model="data.msg">
<h1>{{data.msg}}</h1>
</div>
<div ng-controller="CtrlS">
<input type="text" ng-model="data.msg">
<h1>{{data.msg}}</h1>
</div>
</div><!-- col-sm-8 -->
</div><!-- /container -->
</body>
<html ng-app="myapp">
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<style>
body {
padding-top:30px;
}
</style>
<script src="angular.js"></script>
<script>
angular.module('myapp', [])
.factory("Data", function() {
return {
msg:"hello world"
};
})
.controller("CtrlF", function($scope, Data) {
$scope.data = Data;
})
.controller("CtrlS", function($scope, Data) {
$scope.data = Data;
});
</script>
</head>
<body>
<div class="container">
<div class="col-sm-8 col-sm-offset-2">
<div ng-controller="CtrlF">
<input type="text" ng-model="data.msg">
<h1>{{data.msg}}</h1>
</div>
<div ng-controller="CtrlS">
<input type="text" ng-model="data.msg">
<h1>{{data.msg}}</h1>
</div>
</div><!-- col-sm-8 -->
</div><!-- /container -->
</body>
</html>
效果如图,