मैं 1 index.html के साथ एक सरल एसपीए बनाने की कोशिश करता हूं जिसमें टेम्पलेट शामिल हैं।Angular.js: टेम्पलेट में ng-href का उपयोग कैसे करें?
<a ng-href="#/myPage">myPage</a>
में index.html लेकिन मेरे टेम्पलेट्स में नहीं, लिंक उन पर क्लिक नहीं है काम:
मैं एनजी-href निर्देश के साथ एक समस्या मिला है। लेकिन href अभी भी काम करता है।
<a href="#/myPage">myPage</a>
मेरा ऐप:
index.html:
...
<body ng-app="myApp">
<a ng-href="#/myPage" target="_self">link</a> <!-- work ! -->
<div class="container" ng-view=""></div>
</body>
...
app.js:
'use strict';
angular.module('myApp',
[ 'ngCookies', 'ngResource', 'ngSanitize', 'ngRoute' ]).config(
function($routeProvider) {
$routeProvider.when('/', {
templateUrl : 'views/main.tpl.html',
controller : 'MainCtrl'
})
.when('/myPage', {
templateUrl : 'views/page.tpl.html',
controller : 'MainCtrl'
})
.otherwise({
redirectTo : '/'
});
});
controller.js
'use strict';
myApp.controller('MainCtrl', function() {
this.myColor = 'blue';
});
page.tpl.html
<div>
<a ng-href="#/myPage" target="_self">link</a> <!-- Dont work -->
<a ng-href="#/myPage" target="_self">link</a> <!-- Dont work -->
<a ng-href="#/myPage{{}}">link</a> <!-- Dont work -->
<a ng-href="#/{{ 'myPage' }}">link</a> <!-- Dont work -->
<a href="#/myPage" target="_self">link</a> <!-- Work ! -->
</div>
मैं एनजी-href और क्यों परिणाम href से अलग है के साथ समस्या यह समझ में नहीं आता।
<a ng-href="#/{{myPathVariable}}"/>Take Me Somewhere</a>
कहाँ अपने दायरे में: मैं कोणीय 1,2
ठीक है, लेकिन क्यों link टेम्पलेट्स में काम नहीं करते? – Thomas
यह काम नहीं करेगा क्योंकि आप 'myPage' को गुण – Mike
में चर के बजाय स्ट्रिंग अक्षर के रूप में पास कर रहे हैं, मैं यह सुनिश्चित करने के लिए खाली href टैग जोड़ने की अनुशंसा करता हूं कि ब्राउज़र इसे एक लिंक के रूप में उठाए: Take Me Somewhere –