您的位置:首页技术文章
文章详情页

angular.js - angular js配置路由 编写控制器的时候说跳转页内的数据模型不存在

【字号: 日期:2024-09-19 15:11:51浏览:33作者:猪猪

问题描述

<!DOCTYPE html><html><head> <meta charset='UTF-8'> <title>angular admin test</title><link rel='stylesheet' href='http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css'> <link rel='stylesheet' href='https://www.xxx.com/wenda/index.css'> <link rel='stylesheet' href='https://www.xxx.com/wenda/semantic.min.css'><!-- <base href='https://www.xxx.com/'>--></head><body ng-app='myapp'> <body ng-app='myapp'><p ng-app='admin'><p><p> <span>Admin angular</span></p><p> <!--<a>Download Now</a>--> <button class='btn-download ui inverted basic button'>Download Now</butto></p></p><p><p class='ui inverted vertical menu'> <a href='https://www.xxx.com/wenda/13933.html#/dashboard'> Dashboard</a> <a href='https://www.xxx.com/wenda/13933.html#/charts'> Charts</a> <a href='https://www.xxx.com/wenda/13933.html#/tables'> Tables</a> <a href='https://www.xxx.com/wenda/13933.html#/forms'> Forms</a> <a href='https://www.xxx.com/wenda/13933.html#/elements'> Bootstrap Elements</a> <a href='https://www.xxx.com/wenda/13933.html#/grid'> Bootstap Grid</a> <a href='https://www.xxx.com/wenda/13933.html#/components'> Component</a> <a href='https://www.xxx.com/wenda/13933.html#/menu'> Menu</a> <a href='https://www.xxx.com/wenda/13933.html#/blankpage'> BlankPage</a></p> </p> <p 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;})


出错如下angular.js - angular js配置路由 编写控制器的时候说跳转页内的数据模型不存在


angular.js - angular js配置路由 编写控制器的时候说跳转页内的数据模型不存在


求大神带!!!!!!


问题解答


回答1:

$scope.notecontent是全局变量,但是在使用之前也是要声明的。这个变量在你点击重置按钮之前还没有被定义,虽然你点击之后定义的是全局变量。可以在controller顶部声明一次$scope.notecontent=’’;就行了。


还有个问题,你这代码里有三个ng-app居然运行成功了。。。

相关文章: