• Services 在多个 controller 中共享数据。


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible"content="IE=edge" />
    <meta name="viewport"content="width=device-width,initial-scale=1" />
    <title></title>
    <meta charset="utf-8" />
    <link rel="stylesheet"href="bootstrap-3.3.5/dist/css/bootstrap.min.css" />
    </head>
    <body data-ng-app="myApp">
    <div class="container"style="padding:50px">
    <div data-ng-controller="fCtrl">
    <input type="text"data-ng-model="data.msg" />
    <p>{{data.msg}}</p>
    </div>
    <div data-ng-controller="sCtrl">
    <input type="text"data-ng-model="data.msg" />
    <p>{{data.msg}}</p>
    </div>
    </div>
    <script src="jQuery/jquery-2.1.4.js"></script>
    <script src="bootstrap-3.3.5/dist/js/bootstrap.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
    <script src="js/app1.js"></script>
    </body>
    </html>

    app1.js

    angular.module("myApp", [])
    .factory("Data", function () {
    return {
    msg:"我来自factory"
    }
    })
    .controller("fCtrl", function ($scope,Data) {
    $scope.data = Data;

    })
    .controller("sCtrl", function ($scope,Data) {
    $scope.data = Data;
    })

  • 相关阅读:
    Oracle判断对象是否存在sql语句
    Reporting Services 4: Web Service
    C#的16位和32位MD5加密
    龙的传人Xml_javascript分页
    龙的传人——xml_javascript三级联动
    SAE学习笔记1
    java方法重载
    jquery easyui时间微调器
    django支持ajax的post方法
    easyui插件显示问题
  • 原文地址:https://www.cnblogs.com/melao2006/p/5093256.html
Copyright © 2020-2023  润新知