我的問題涉及如何在AngularJS應用程序中的ngView
內調用模板中使用AngularJS directives
。ngView內部的模板調用不支持角度指令stackoverflow
定義:
該應用程序是單頁,所以加載包含在與所述NG-視圖屬性的DOM div元素(模板URL)一個index.html。
Main Page(
的index.html) :
<html data-ng-app="App" data-ng-controller="AppCtrl">
<head>
<title>Angular App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<!-- primary nav -->
<a href="#/page1">Page 1</a>
<a href="#/page2">Page 2</a>
<a href="#/page3">Page 3</a>
<!-- display the view -->
<div ng-view>
</div>
</body>
</html>
app.js:
angular.module('App', [])
.controller('AppCtrl', function($rootScope, appLoading) {
$rootScope.topScope = $rootScope;
$rootScope.$on('$routeChangeStart', function() {
appLoading.loading();
});
})
.config(function($routeProvider) {
$routeProvider.when('/page1', {
controller : 'Page1Ctrl',
templateUrl : 'page1.html'
})
.when('/page2', {
controller : 'Page2Ctrl',
templateUrl : 'page2.html'
})
.when('/page3', {
controller : 'Page3Ctrl',
templateUrl : 'page3.html'
})
.otherwise({
redirectTo: '/home'
});
})
page1.html:
<div class="form">
<form class="login-profile" method="post" action="" name="editfrm">
<input type="text" name="email" value="" id="txtemail" data-ng-model="email" required>
<input type="password" name="password" value="" id="txtpassword" data-ng-model="password" required>
<input type="button" value="Save" name="submit">
</form>
</div>
問題: 模板Url在ngView
內部調用不支持任何AngularJS deirective
。 data-ng-model="email"
& data-ng-model="password"
在ngView呼籲點擊鏈接<a href="#/page1">Page 1</a>
任何幫助不工作時可以理解的。謝謝
@MikkoViitala,能否請你幫我精心更多的評論。 –
是的,發佈Page1Ctrl的JS代碼。 –