使用 angularJS 路由 link 创建 php 元素
create php element with angularJS route link
我使用 php 创建了这个 html 元素:
echo
"<button
type ='button' class='login-btn login'
onclick = 'location.href='#!login';'>
Login
</button>";
当我点击它时,我想使用 angularJS 重定向到登录页面。如果它是一个常规的 html 元素,它可以成功运行,但是由于我修改了 '' , " "
以使用 php 创建它,所以我的 link 不起作用。
我收到错误:Uncaught SyntaxError: Unexpected end of input
for location.href
这是我的 angularJS 文件,可以更详细地查看:
angModule.js
const app = angular.module("myApp" , ["ngRoute"]);
app.config(($routeProvider)=>{
$routeProvider
.when("/" , {templateUrl:"main.php"})
.when("/login" , {templateUrl : "login.php"})
.when("/register" , {templateUrl : "register.php"});
});
非常感谢你的帮助。
您需要更改 onclick = 'location.href='#!login';'
中的引号:
echo
"<button
type ='button' class='login-btn login'
onclick = 'location.href=\"#!login\";'>
Login
</button>";
('#!login'
的第一个引号终止了 'location.href=
的引号)
有关 PHP 个字符串的更多信息:https://www.php.net/manual/en/language.types.string.php
我使用 php 创建了这个 html 元素:
echo
"<button
type ='button' class='login-btn login'
onclick = 'location.href='#!login';'>
Login
</button>";
当我点击它时,我想使用 angularJS 重定向到登录页面。如果它是一个常规的 html 元素,它可以成功运行,但是由于我修改了 '' , " "
以使用 php 创建它,所以我的 link 不起作用。
我收到错误:Uncaught SyntaxError: Unexpected end of input
for location.href
这是我的 angularJS 文件,可以更详细地查看:
angModule.js
const app = angular.module("myApp" , ["ngRoute"]);
app.config(($routeProvider)=>{
$routeProvider
.when("/" , {templateUrl:"main.php"})
.when("/login" , {templateUrl : "login.php"})
.when("/register" , {templateUrl : "register.php"});
});
非常感谢你的帮助。
您需要更改 onclick = 'location.href='#!login';'
中的引号:
echo
"<button
type ='button' class='login-btn login'
onclick = 'location.href=\"#!login\";'>
Login
</button>";
('#!login'
的第一个引号终止了 'location.href=
的引号)
有关 PHP 个字符串的更多信息:https://www.php.net/manual/en/language.types.string.php