角度链接标记使用自定义服务

时间:2016-01-27 16:54:50

标签: angularjs

我的应用程序使用ngRoute,因此当点击链接时,页面会在ngView中注入 因此,我利用页面控制器,以便在访问页面时触发“TogglerFactory”服务 每当不仅在第一次访问页面时点击链接,我如何调用此服务的menuToggle()。感谢

<!doctype html>
<html lang="en" ng-app="appModule">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <base href="http://localhost:63342/students/">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.js"></script>
    <script src="https://code.angularjs.org/1.5.0-rc.1/angular-animate.js"></script>
    <meta name="viewport" content="width=device-width" />

    <script src="app.js"></script>

    <script src="services/routing.js"></script>
    <script src="services/menuToggle.js"></script>

    <script src="controllers/menuToggleCtrl.js"></script>
    <script src="controllers/mainMenuCtrl.js"></script>
    <script src="controllers/page1Ctrl.js"></script>
    <script src="controllers/page2Ctrl.js"></script>
</head>

<body>
<header ng-controller="MenuToggleCtrl">
    <button class="menuLeft" type="button" ng-model="clicked" ng-click="menuToggle()">&#9776;</button>
    <label id="pageTitle" class="pageTitle">Select item from list</label>
    <button class="menuRight" type="button">&#8942;</button>
</header>

<section class="mainMenu" ng-controller="MainMenuCtrl" ng-if="!clicked">
    <ul>
        <li ng-repeat="item in menuItems">
            <a href="#/{{item.name}}">
                <image ng-src="images/{{item.image}}.png"></image>
                {{item.name}}
            </a>
        </li>
    </ul>
</section>

<main ng-view></main>

<footer ng-controller="MenuToggleCtrl" ng-if="clicked">
    <ul class="horizontal-style">
        <li><button type="button">NO</button></li>
        <li><button type="button">EXTRA</button></li>
        <li><button type="button">YES</button></li>
    </ul>
</footer>

</body>
</html>


<!-- begin snippet: js hide: false -->
guard let touch = object.AnyObject() as? UITouch, let picker = touch.view as? UIPickerView else {
    return //Do Nothing
}
//Do something with picker

0 个答案:

没有答案