【问题标题】:Is AngularJS Working in Wordpress PluginAngularJS 在 Wordpress 插件中工作吗
【发布时间】:2016-11-27 07:43:06
【问题描述】:

我正在为 wordpress 开发一个 AngularJS 插件。我只是看不到 Angular 在 Wordpress 中工作。我错了还是有任何将Angular集成到Wordpress的特定方法。我正确地将所有必需的 Angular 文件排入队列,但由于它没有锻炼,然后我将一个普通的 JS 文件排入队列以确保我没有做错任何事情。甚至 Angular 都不起作用,我的普通 JS 文件也起作用了。请给我一个解释。


添加我的代码

插件文件入队脚本

wp_enqueue_script('angular', plugins_url('/libraries/angular_material/node_modules/angular/angular.js', __FILE__), array(''));

wp_enqueue_script('plugin-scripts', plugins_url('/js/plugin.js', __FILE__), array('angular'));

plugin.js 文件

var my_app = angular.module('myApp', ['ngMaterial', 'ngMessages', 'angular-loading-bar', 'ngAnimate']);

my_app.controller('myCtrl', ["$scope", "$http", "$window", "$mdDialog", function ($scope, $http, $window, $mdDialog) {

        $scope.test = function () {
            alert("OK");
        };

    }]);

前端标记PHP文件

<div class="layout_parent" ng-app="myApp" ng-controller="myCtrl">

<button ng-click="test();" class="btn btn-success">Submit</button>

</div>

提前非常感谢大家。

最好的问候, 尼曼莎·佩雷拉

【问题讨论】:

  • 没有理由它不应该工作。我在 wordpress 中添加了许多 Angular 应用程序。
  • 到 Wordpress 插件??
  • 是的。如果没有更多的错误或冲突细节,没有人能真正帮助你
  • 非常感谢您的及时回复。我没有冲突。没有错误。我只是添加了一个简单的警报功能。让我用代码编辑问题。
  • 脚本是否在页面中正确加载?看到按钮了吗?

标签: javascript php angularjs wordpress plugins


【解决方案1】:

您可以通过 WP JSON API 插件将 AngularJS 前端与 WordPress 后端集成有一些不同的方法。 http://studioraygun.co.uk/blog/web-development/angularjs-front-end-wordpress-back-end/

但是,您似乎正在使用这种激活 WP-API 插件并直接将脚本入队的方法。

wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) );

https://developer.wordpress.org/rest-api/using-the-rest-api/backbone-javascript-client/

【讨论】:

    猜你喜欢
    • 2015-10-21
    • 1970-01-01
    • 2023-04-06
    • 2017-09-24
    • 2013-09-29
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多