我刚接触到角,我就要用jsfiddlle写我的第一个hello world应用程序了。我通过使用ng-include成功地加载了内容,但是使用ngRoute仍然有问题:
无法读取未定义的属性“insertBefore”
在以下代码中:HTML
<div ng-app="myApp">
<a href="#/firstPanel">1Panel</a>
<a href="#/secondPanel">2Panel</a>
<div ng-include src="'main.html'"><div>
<div ng-view></div>
<script type="text/ng-template" id="first_panel.html">
First Panel
</script>
<script type="text/ng-template" id="second_panel.html">
Second Panel
</script>
<script type="text/ng-template" id="main.html">
<div ng-controller="MainCtrl as mainCtrl">
Main {{mainCtrl.foo}} <br/>
<input type="text" ng-model="mainCtrl.foo"/>
<br/>
</div>
</script>
</div>JS
var myApp = angular.module('myApp', ['ngRoute']);
var my = {};
my.MainCtrl = function() {
this.foo = 'foo';
}
my.SecondPanelCtrl = function() {
}
my.FirstPanelCtrl = function() {
}
var routeProvider = function($routeProvider) {
$routeProvider.
when('/firstPanel', {
templateUrl: 'first_panel.html',
controller: 'FirstPanelCtrl',
controllerAs: 'firstPanelCtrl'
}).
when('/secondPanel', {
templateUrl: 'second_panel.html',
controller: 'SecondPanelCtrl',
controllerAs: 'secondPanelCtrl'
}).
otherwise({redirectTo: '/firstPanel'});
};
myApp.config(routeProvider);
// register all controllers
myApp.controller('MainCtrl', my.MainCtrl);
myApp.controller('FirstPanelCtrl', my.FirstPanelCtrl);
myApp.controller('SecondPanelCtrl', my.SecondPanelCtrl);这是我的小提琴:
http://jsfiddle.net/ccTd6/14/
发布于 2014-05-24 17:34:03
是HTML语法中的一个错误把事情搞砸了:
<div ng-include src="'main.html'"></div>
^
here you missed the `/`__|注:
至少在我尝试过的Chrome中,是浏览器混淆并完全删除了ngView div,所以它在任何情况下都不是角的错误。
https://stackoverflow.com/questions/23847568
复制相似问题