angular.js - angular js配置路由 寫控制器的時候說跳轉頁內的資料模型不存在
我想大声告诉你
我想大声告诉你 2017-05-15 17:11:26
0
1
602
   <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>angular admin test</title>
    <script src="angularJs/angular.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular-animate.min.js"></script>
    <script src="app.js"></script>
    <!--    <script src="controller2.js"></script>-->
    <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css">
    <link rel="stylesheet" href="semantic.min.css">

    <!--    <base href="/">-->
</head>

<body ng-app="myapp">

    <body ng-app="myapp">
        <p ng-app="admin">
            <p class="header">
                <p class="top-left">
                    <span>Admin angular</span>
                </p>
                <p class="top-right">
                    <!--                <a class="btn-download">Download Now</a>-->
                    <button class="btn-download ui inverted basic button">
                        Download Now
                        </butto>
                </p>
            </p>
            <p class="left">
                <p class="ui inverted vertical menu">
                    <a class="item" href="#/dashboard">
                    Dashboard
                </a>
                    <a class=" item" href="#/charts">
                    Charts
                </a>
                    <a class=" item" href="#/tables">
                    Tables
                </a>
                    <a class=" item" href="#/forms">
                   Forms
                </a>
                    <a class=" item" href="#/elements">
                    Bootstrap Elements
                </a>
                    <a class=" item" href="#/grid">
                    Bootstap Grid
                </a>
                    <a class=" item" href="#/components">
                    Component
                </a>
                    <a class=" item" href="#/menu">
                    Menu
                </a>
                    <a class=" item" href="#/blankpage">
                    BlankPage
                </a>
                </p>
            </p>
            <p class="content" ng-view></p>
        </p>
    </body>

</html>

app.js設定路由的

var app = angular.module('myapp', ['ngRoute', 'ngAnimate'])

//app.value('defaultcount', 100)

app.config(function ($routeProvider) {
    //    $locationProvider.html5Mode(true)
    $routeProvider.when('/dashboard', {
            templateUrl: 'dashboard.html',
            controller: 'dashboard',
            authenticate: true
        })
        //    $routeProvider.when('/charts', {
        //        templateUrl: 'charts.html',
        //    })
        //    $routeProvider.when('/tables', {
        //        templateUrl: 'tables.html',
        //    })
        //    $routeProvider.when('/forms', {
        //        templateUrl: 'forms.html',
        //    })
})
app.controller('dashboard', function ($scope) {
    $scope.save = function () {
        alert('success')
    }
    $scope.reset = function () {
        $scope.notecontent = ""
    }

    $scope.count = 100 - $scope.notecontent.length;
})

出錯如下

求大神帶! ! ! ! ! !

我想大声告诉你
我想大声告诉你

全部回覆(1)
阿神

$scope.notecontent是全域變量,但是在使用前也是要聲明的。這個變數在你點擊重置按鈕之前還沒有被定義,雖然你點擊之後定義的是全域變數。可以在controller頂部聲明$scope.notecontent='';就行了。

還有個問題,你這程式碼裡有三個ng-app居然運作成功了。 。 。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板